aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-04-06 15:43:07 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-04-06 15:43:07 +0200
commitd3b2b979e01abada891500056b1a0b823faede45 (patch)
treeaf0116529791ae6c289ea2363da31b4b90e1887c
parente5305e691ffa53ec33efaa456a90f06124861065 (diff)
Corrected a few things.
-rw-r--r--client/main.cpp2
-rw-r--r--daemon/ip/if.c133
-rw-r--r--daemon/ip/internals.h7
-rw-r--r--daemon/server.c28
-rw-r--r--include/wesh.hpp7
-rw-r--r--lib/helpers.cpp2
-rw-r--r--lib/internals.hpp1
-rw-r--r--lib/wes.cpp14
-rw-r--r--weshd.x8
9 files changed, 121 insertions, 81 deletions
diff --git a/client/main.cpp b/client/main.cpp
index a47faec..d330e3e 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -34,7 +34,7 @@ static void tests(void)
const unsigned char ip[4] = {192, 168, 1, 111};
wesh::wes wes; struct tm dt;
- wes.craft(ip);
+ wes.gather(ip);
dt = wes.get_date();
std::cout << std::endl
diff --git a/daemon/ip/if.c b/daemon/ip/if.c
index bfaeae8..1331beb 100644
--- a/daemon/ip/if.c
+++ b/daemon/ip/if.c
@@ -61,13 +61,8 @@ static int free_ip_wes(wes_t *wes)
clear_config(wes);
/* FIXME: clear_data(wes); */
-/* FIXME: peut-être faire en sorte que ceci n'utilise pas l'alloc. dyn. ?
set_http_ident(wes, NULL, NULL);
set_ftp_ident(wes, NULL, NULL);
-*/
-
- free(wes->http_data);
- free(wes->ftp_data);
deinit_wes_base(wes);
free(wes);
@@ -99,10 +94,12 @@ static int make_ip_wes(wes_t **wesp, wescreatedata_t *data)
wes->sections = NULL;
wes->data = NULL;
- wes->http_data = NULL;
- wes->ftp_data = NULL;
wes->http_handle = NULL;
wes->ftp_handle = NULL;
+ wes->http_name = NULL;
+ wes->http_pass = NULL;
+ wes->ftp_name = NULL;
+ wes->ftp_pass = NULL;
/* TODO: use `data` here */
@@ -192,69 +189,107 @@ int add_ip_wes(weslist_t *list, wes_t **wesp, wescreatedata_t *data)
* Petits utilitaires (TODO: à déplacer, quelque chose ?)
* --- */
-#define DEFAULT_HTTP_NAME "admin"
-#define DEFAULT_HTTP_PASS "wes"
-#define DEFAULT_FTP_NAME "adminftp"
-#define DEFAULT_FTP_PASS "wesftp"
+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 *name, const char *pass)
+int set_http_ident(wes_t *wes, const char *namep, const char *passp)
{
- size_t namesz, passsz;
+ char *name = NULL, *pass = NULL;
+ size_t sz;
- if (wes->http_data)
- free(wes->http_data);
+ /* Nouveau nom d'utilisateur. */
- wes->http_data = NULL;
- wes->http_name = NULL;
- wes->http_pass = NULL;
+ 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);
- if (!name)
- name = DEFAULT_HTTP_NAME;
- if (!pass)
- pass = DEFAULT_HTTP_PASS;
+ memcpy(name, namep, sz);
+ }
- namesz = strlen(name) + 1;
- passsz = strlen(pass) + 1;
- if (!(wes->http_data = malloc(namesz + passsz + 2)))
- return (WRALLOC);
+ /* 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);
+ }
- memcpy(wes->http_data, name, namesz);
- memcpy(&wes->http_data[namesz], pass, passsz);
- wes->http_name = wes->http_data;
- wes->http_pass = &wes->http_data[namesz];
+ /* 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 *name, const char *pass)
+int set_ftp_ident(wes_t *wes, const char *namep, const char *passp)
{
- size_t namesz, passsz;
+ char *name = NULL, *pass = NULL;
+ size_t sz;
- if (wes->ftp_data)
- free(wes->ftp_data);
+ /* Nouveau nom d'utilisateur. */
- wes->ftp_data = NULL;
- wes->ftp_name = NULL;
- wes->ftp_pass = NULL;
+ 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);
- if (!name)
- name = DEFAULT_FTP_NAME;
- if (!pass)
- pass = DEFAULT_FTP_PASS;
+ memcpy(name, namep, sz);
+ }
- namesz = strlen(name) + 1;
- passsz = strlen(pass) + 1;
- if (!(wes->ftp_data = malloc(namesz + passsz + 2)))
- return (WRALLOC);
+ /* 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);
- memcpy(wes->ftp_data, name, namesz);
- memcpy(&wes->ftp_data[namesz], pass, passsz);
- wes->ftp_name = wes->ftp_data;
- wes->ftp_pass = &wes->ftp_data[namesz];
+ wes->ftp_name = name;
+ wes->ftp_pass = pass;
return (WROK);
}
diff --git a/daemon/ip/internals.h b/daemon/ip/internals.h
index 210e5d0..15b8df4 100644
--- a/daemon/ip/internals.h
+++ b/daemon/ip/internals.h
@@ -230,18 +230,13 @@ typedef struct wescgiarg {
struct wes {
wesbase_t base;
- /* Identifiants pour les serveurs HTTP et FTP.
- * `auth_data` est la zone allouée pour cela. Elle contient les
- * terminating zeroes, histoire que les chaînes soient disponibles
- * directement. */
+ /* Identifiants pour les serveurs HTTP et FTP. */
char *http_name;
char *http_pass;
- char *http_data;
char *ftp_name;
char *ftp_pass;
- char *ftp_data;
/* Canaux (handles de la libcurl) pour le HTTP et FTP. */
diff --git a/daemon/server.c b/daemon/server.c
index a3771cd..b50c4cb 100644
--- a/daemon/server.c
+++ b/daemon/server.c
@@ -65,9 +65,10 @@ static jmp_buf endjmp;
* Gestion des ressources existentes.
* --- */
-/* `register_new_1_svc()`: Création de ressource. */
+/* `gather_1_svc()`: Création de ressource, ou récupération de ressource
+ * existante. */
-wespret_with_id_t *register_new_1_svc(wespregopts_t *args,
+wespret_with_id_t *gather_1_svc(wespregopts_t *args,
struct svc_req *req)
{
static wespret_with_id_t resp;
@@ -129,21 +130,34 @@ wespret_with_id_t *register_new_1_svc(wespregopts_t *args,
break;
}
- /* TODO: identifiants */
+ /* On définit les identifiants. */
+
+ data.http_username = args->http_username;
+ data.http_password = args->http_password;
+ data.ftp_username = args->ftp_username;
+ data.ftp_password = args->ftp_password;
/* On ajoute la ressource en utilisant la fonction dédiée de l'interface
* choisie par le client. */
- if ((err = (*addfunc)(list, &wes, &data))) {
- /* TODO: vérification de l'erreur */
+ switch ((err = (*addfunc)(list, &wes, &data))) {
+ case WROK:
+ msg((wlinfo, "success in creating the resource!"));
+ break;
+
+ case WREXISTS:
+ msg((wlinfo, "success in gathering existing resource!"));
+ break;
+
+ default:
+ msg((wlerror, "error while adding: %s", error_string(err)));
+
resp.ret = WESPRET_INT;
return (&resp);
}
/* On a tout, on peut donner un petit sourire au client :) */
- msg((wlinfo, "success in adding resource!"));
-
resp.ret = WESPRET_OK;
resp.id = wes->id;
return (&resp);
diff --git a/include/wesh.hpp b/include/wesh.hpp
index 4a9ff92..065088e 100644
--- a/include/wesh.hpp
+++ b/include/wesh.hpp
@@ -72,7 +72,6 @@ WESH_EXC(not_implemented_exception,
"L'appel correspondant n'est pas implémenté.")
WESH_EXC(not_loaded_exception, "Cet objet n'a pas été chargé.")
WESH_EXC(already_created_exception, "Cet objet a déjà été créé !")
-WESH_EXC(already_exists_exception, "Un objet similaire existe déjà !")
WESH_EXC(no_exists_exception,
"Il n'y a pas de serveur WES avec cet identifiant.")
WESH_EXC(unavailable_exception, "Le serveur WES est injoignable.")
@@ -161,10 +160,10 @@ public:
/* Créer et supprimer un serveur WES de la liste de gestion du démon. */
- void craft(const unsigned char ip[4]);
- void craft(const unsigned char ip[4],
+ void gather(const unsigned char ip[4]);
+ void gather(const unsigned char ip[4],
std::string username, std::string password);
- void craft(const unsigned char ip[4],
+ void gather(const unsigned char ip[4],
std::string http_username, std::string http_password,
std::string ftp_username, std::string ftp_password);
void remove(void);
diff --git a/lib/helpers.cpp b/lib/helpers.cpp
index bb182a9..3445e46 100644
--- a/lib/helpers.cpp
+++ b/lib/helpers.cpp
@@ -41,8 +41,6 @@ void throw_exception_using_ret(wespret_t ret)
break;
case WESPRET_IMP:
throw not_implemented_exception();
- case WESPRET_EXS:
- throw already_exists_exception();
case WESPRET_NOW:
throw no_exists_exception();
case WESPRET_CON:
diff --git a/lib/internals.hpp b/lib/internals.hpp
index 07edbec..c4dff79 100644
--- a/lib/internals.hpp
+++ b/lib/internals.hpp
@@ -36,6 +36,7 @@
extern "C" {
# include <weshd.h>
+# undef gather
}
/* Utilitaires. */
diff --git a/lib/wes.cpp b/lib/wes.cpp
index 0e7d1e1..eadd50f 100644
--- a/lib/wes.cpp
+++ b/lib/wes.cpp
@@ -77,7 +77,7 @@ int wes::get_id(void)
* Création et suppression de la ressource.
* --- */
-void wes::craft(const unsigned char ip[4],
+void wes::gather(const unsigned char ip[4],
std::string http_username, std::string http_password,
std::string ftp_username, std::string ftp_password)
{
@@ -99,7 +99,7 @@ void wes::craft(const unsigned char ip[4],
strcpy(fu, ftp_username.c_str());
strcpy(fp, ftp_password.c_str());
- args.type = /* WESPREGTYPE_IP */ WESPREGTYPE_DUMMY;
+ args.type = WESPREGTYPE_IP;
args.ip.type = WESPIPTYPE_4;
args.ip.ipv4[0] = ip[0];
args.ip.ipv4[1] = ip[1];
@@ -110,7 +110,7 @@ void wes::craft(const unsigned char ip[4],
args.ftp_username = fu;
args.ftp_password = fp;
- resp = register_new_1(&args, clnt(this));
+ resp = gather_1(&args, clnt(this));
if (!resp)
throw connexion_exception();
}
@@ -122,15 +122,15 @@ void wes::craft(const unsigned char ip[4],
this->id = resp->id;
}
-void wes::craft(const unsigned char ip[4],
+void wes::gather(const unsigned char ip[4],
std::string username, std::string password)
{
- this->craft(ip, username, password, username, password);
+ this->gather(ip, username, password, username, password);
}
-void wes::craft(const unsigned char ip[4])
+void wes::gather(const unsigned char ip[4])
{
- this->craft(ip, "admin", "wes", "adminftp", "wesftp");
+ this->gather(ip, "admin", "wes", "adminftp", "wesftp");
}
void wes::remove(void)
diff --git a/weshd.x b/weshd.x
index 7bb1920..b1a51da 100644
--- a/weshd.x
+++ b/weshd.x
@@ -34,7 +34,6 @@
* - `WESRET_IMP`: cette fonctionnalité n'est pas (encore) implémentée.
* - `WESRET_VAL`: arguments invalides pour cette fonctionnalité.
*
- * - `WESRET_EXS`: la ressource dont la création a été demandée existe déjà.
* - `WESRET_NOW`: la ressource n'existe pas.
* - `WESRET_CON`: le serveur n'a pas pu être joint. */
@@ -44,9 +43,8 @@ enum wespret_t {
WESPRET_IMP = 2,
WESPRET_VAL = 3,
- WESPRET_EXS = 10,
- WESPRET_NOW = 11,
- WESPRET_CON = 12
+ WESPRET_NOW = 10,
+ WESPRET_CON = 11
};
/* Un identifiant d'une ressource de type serveur WES est un entier
@@ -324,7 +322,7 @@ program WESHD_PROG {
version WESHD_VERS1 {
/* Gérer les ressources existantes. */
- wespret_with_id_t register_new(wespregopts_t args) = 1;
+ wespret_with_id_t gather(wespregopts_t args) = 1;
wespret_t unregister(wespid_t id) = 2;
/* Récupérer et définir le nom d'hôte du serveur WES. */