asciification du code source
This commit is contained in:
76
guinnessd.c
76
guinnessd.c
@@ -68,23 +68,23 @@ void install_handler ();
|
||||
void handler_signaux (int sig) {
|
||||
switch (sig) {
|
||||
case SIGPIPE:
|
||||
printlog (LOG_NOTIFY, "Signal SIGPIPE reçu...\n");
|
||||
printlog (LOG_NOTIFY, "Signal SIGPIPE recu...\n");
|
||||
install_handler ();
|
||||
break;
|
||||
case SIGTERM:
|
||||
case SIGQUIT:
|
||||
case SIGINT:
|
||||
online = FALSE;
|
||||
printlog (LOG_NOTIFY, "Signal de terminaison reçu...\n");
|
||||
printlog (LOG_NOTIFY, "Signal de terminaison recu...\n");
|
||||
break;
|
||||
default:
|
||||
printlog (LOG_NOTIFY, "Signal reçu...\n");
|
||||
printlog (LOG_NOTIFY, "Signal recu...\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Lecture du fichier de config : récupération des valeurs
|
||||
* Lecture du fichier de config : recuperation des valeurs
|
||||
*
|
||||
*/
|
||||
char *get_string_from_token (char *line) {
|
||||
@@ -154,13 +154,13 @@ void Usage (int help) {
|
||||
if (help)
|
||||
printf ("Usage : guinnessd [-h] [-v] [-b] [-p port] "
|
||||
"[-s passwd] [-d chemin] [-l fichier] [-f fichier]\n"
|
||||
" -h : aide sur les paramètres\n"
|
||||
" -h : aide sur les parametres\n"
|
||||
" -v : affiche la version\n"
|
||||
" -b : détache le serveur du terminal\n"
|
||||
" -a adresse : spécifie l'adresse du serveur\n"
|
||||
" -p port : spécifie le numéro du port\n"
|
||||
" -s passwd : spécifie le mot de passe d'aministration\n"
|
||||
" -d chemin : indique le chemin où se"
|
||||
" -b : detache le serveur du terminal\n"
|
||||
" -a adresse : specifie l'adresse du serveur\n"
|
||||
" -p port : specifie le numero du port\n"
|
||||
" -s passwd : specifie le mot de passe d'aministration\n"
|
||||
" -d chemin : indique le chemin ou se"
|
||||
" trouvent les ascii-arts\n"
|
||||
" -l fichier : fichier de log\n"
|
||||
" -f fichier : fichier de configuration\n\n");
|
||||
@@ -176,7 +176,7 @@ int traite_argv (int argc, char *argv[]) {
|
||||
int option;
|
||||
int detach = FALSE;
|
||||
|
||||
/* Vérification des paramètres */
|
||||
/* Verification des parametres */
|
||||
while ((option = getopt (argc, argv, "hvba:p:s:d:l:f:")) != -1) {
|
||||
switch (option) {
|
||||
case 'h' :
|
||||
@@ -260,7 +260,7 @@ int initiate (int socket_service, userinfos *infos) {
|
||||
|
||||
memset (userdatas, 0, MAXSTRLEN);
|
||||
|
||||
/* Récupération des infos sur le connecté */
|
||||
/* Recuperation des infos sur le connecte */
|
||||
get_sock_infos (socket_service,
|
||||
&nom_distant, &ip_distant,
|
||||
&port_local, &port_distant);
|
||||
@@ -284,18 +284,18 @@ int initiate (int socket_service, userinfos *infos) {
|
||||
if ( (cont = send_servercmds (socket_service)) == FALSE)
|
||||
return cont;
|
||||
|
||||
/* 2. attente des données du connecté */
|
||||
/* 2. attente des donnees du connecte */
|
||||
if ( (cont = read_infos (socket_service, userdatas)) == FALSE)
|
||||
return cont;
|
||||
|
||||
/* FIN DU PROTOCOLE : Véricifations / ajout dans la liste / affichage */
|
||||
/* FIN DU PROTOCOLE : Vericifations / ajout dans la liste / affichage */
|
||||
datas = xstrdup (userdatas);
|
||||
|
||||
/* Nom d'utilisateur */
|
||||
token = strtok_r (datas, delim, &saveptr);
|
||||
snprintf (infos->nom, MAXSTRLEN, "%s", token ? token : pseudo);
|
||||
|
||||
/* Boisson préférée */
|
||||
/* Boisson preferee */
|
||||
token = strtok_r (NULL, delim, &saveptr);
|
||||
snprintf (infos->prefb, MAXSTRLEN, "%s", token ? token : drink);
|
||||
|
||||
@@ -309,7 +309,7 @@ int initiate (int socket_service, userinfos *infos) {
|
||||
strftime (infos->cxdate, MAXSTRLEN, "%a %d %b %Y %T", today);
|
||||
|
||||
printlog (LOG_NOTIFY, "Utilisateur : [%s]\n", infos->nom);
|
||||
printlog (LOG_NOTIFY, "Boisson préférée : [%s]\n", infos->prefb);
|
||||
printlog (LOG_NOTIFY, "Boisson preferee : [%s]\n", infos->prefb);
|
||||
printlog (LOG_NOTIFY, "Message de logout : [%s]\n", infos->logout);
|
||||
printlog (LOG_NOTIFY, "Date de connexion : [%s]\n", infos->cxdate);
|
||||
|
||||
@@ -318,8 +318,8 @@ int initiate (int socket_service, userinfos *infos) {
|
||||
char nick_ok[MAXSTRLEN+1];
|
||||
snprintf (nick_ok, MAXSTRLEN, "@%s", infos->nom);
|
||||
snprintf (infos->nom, MAXSTRLEN, "%s", nick_ok);
|
||||
send_infos (socket_service, "@Pseudo déjà utilisé !\n");
|
||||
printlog (LOG_NOTIFY, "Pseudo déjà utilisé => %s\n", infos->nom);
|
||||
send_infos (socket_service, "@Pseudo deja utilise !\n");
|
||||
printlog (LOG_NOTIFY, "Pseudo deje utilise => %s\n", infos->nom);
|
||||
pthread_mutex_unlock (&mutex_clients);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -329,8 +329,8 @@ int initiate (int socket_service, userinfos *infos) {
|
||||
|
||||
if (! exist_elt (drinks_list, infos->prefb))
|
||||
send_infos (socket_service,
|
||||
"Votre boisson préférée n'est pas disponible sur ce"
|
||||
" serveur !\nVous aurez des Guinness à la place.\n");
|
||||
"Votre boisson preferee n'est pas disponible sur ce"
|
||||
" serveur !\nVous aurez des Guinness a la place.\n");
|
||||
|
||||
/* Passage en mode non bloquant */
|
||||
fcntl (socket_service, F_SETFL, O_NONBLOCK);
|
||||
@@ -369,13 +369,13 @@ void thread_service (int *sock_serv) {
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printlog (LOG_NOTIFY, "Prêt à recevoir des commandes.\n");
|
||||
printlog (LOG_NOTIFY, "Pret a recevoir des commandes.\n");
|
||||
#endif
|
||||
|
||||
while (cont == TRUE) {
|
||||
memset (commande, 0, MAXSTRLEN + 1);
|
||||
|
||||
/* Lecture des caractères reçus */
|
||||
/* Lecture des caracteres recus */
|
||||
do {
|
||||
sleep (1);
|
||||
nb = read (socket_service, commande, MAXSTRLEN);
|
||||
@@ -384,7 +384,7 @@ void thread_service (int *sock_serv) {
|
||||
if ( (errno == EPIPE) || (nb == 0) ) {
|
||||
cont = FALSE;
|
||||
} else {
|
||||
printlog (LOG_ERROR, "Erreur de connexion réception !\n");
|
||||
printlog (LOG_ERROR, "Erreur de connexion reception !\n");
|
||||
}
|
||||
}
|
||||
} while ( (cont != FALSE) &&
|
||||
@@ -392,7 +392,7 @@ void thread_service (int *sock_serv) {
|
||||
(new_message (old_id) != TRUE) );
|
||||
|
||||
#ifdef DEBUG
|
||||
printlog (LOG_NOTIFY, "Commande reçue.\n");
|
||||
printlog (LOG_NOTIFY, "Commande recue.\n");
|
||||
#endif
|
||||
if (cont == TRUE) {
|
||||
/* Traitement de la commande */
|
||||
@@ -403,7 +403,7 @@ void thread_service (int *sock_serv) {
|
||||
old_id = get_broadcastid ();
|
||||
cont = send_broadcast (socket_service, &infos);
|
||||
#ifdef DEBUG
|
||||
printlog (LOG_ERROR, "Émission broadcast pour %s (id = %ld)\n",
|
||||
printlog (LOG_ERROR, "Emission broadcast pour %s (id = %ld)\n",
|
||||
infos.nom, old_id);
|
||||
#endif
|
||||
}
|
||||
@@ -436,7 +436,7 @@ void install_handler () {
|
||||
|
||||
|
||||
/*
|
||||
* Initialisation générale
|
||||
* Initialisation generale
|
||||
*
|
||||
*/
|
||||
void guinnessd_init (int argc, char *argv[]) {
|
||||
@@ -445,11 +445,11 @@ void guinnessd_init (int argc, char *argv[]) {
|
||||
setlocale (LC_ALL, "");
|
||||
install_handler ();
|
||||
|
||||
/* Valeurs par défaut */
|
||||
/* Valeurs par defaut */
|
||||
logfile = stdout;
|
||||
outerr = stderr;
|
||||
|
||||
/* Traitement des paramètres */
|
||||
/* Traitement des parametres */
|
||||
if (traite_argv (argc, argv) == TRUE) {
|
||||
switch (fork()) {
|
||||
case -1: /* erreur */
|
||||
@@ -458,7 +458,7 @@ void guinnessd_init (int argc, char *argv[]) {
|
||||
case 0: /* le fils */
|
||||
setsid ();
|
||||
break;
|
||||
default: /* le père */
|
||||
default: /* le pere */
|
||||
exit (0);
|
||||
}
|
||||
}
|
||||
@@ -466,12 +466,12 @@ void guinnessd_init (int argc, char *argv[]) {
|
||||
/* Lecture du fichier de configuration */
|
||||
load_config ();
|
||||
|
||||
/* Initialisation des sémaphores */
|
||||
/* Initialisation des semaphores */
|
||||
pthread_mutexattr_init (&mutex_attr);
|
||||
pthread_mutex_init (&mutex_broadcast, &mutex_attr);
|
||||
pthread_mutex_init (&mutex_clients, &mutex_attr);
|
||||
|
||||
/* Affectation des paramètres */
|
||||
/* Affectation des parametres */
|
||||
if (IS_NOT_GOOD (pseudo)) SET_STRING (pseudo, DEFAULT_PSEUDO);
|
||||
if (IS_NOT_GOOD (drink)) SET_STRING (drink, DEFAULT_DRINK);
|
||||
if (IS_NOT_GOOD (logout)) SET_STRING (logout, DEFAULT_LOGOUT);
|
||||
@@ -488,7 +488,7 @@ void guinnessd_init (int argc, char *argv[]) {
|
||||
/* Option pour le buffer de logs */
|
||||
setvbuf (logfile, NULL, _IOLBF, 0);
|
||||
|
||||
/* Création de la liste de boissons par défaut*/
|
||||
/* Creation de la liste de boissons par defaut*/
|
||||
add_elt (&drinks_list, "guinness");
|
||||
|
||||
if (! chemin) chemin = xstrdup (DRINKS_DIR);
|
||||
@@ -510,7 +510,7 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
guinnessd_init (argc, argv);
|
||||
|
||||
/* Installation de l'écoute du serveur */
|
||||
/* Installation de l'ecoute du serveur */
|
||||
if ( (socket_ecoute = install_server (port, adr_ip, NULL)) == -1) {
|
||||
printlog (LOG_ERROR, "Impossible d'installer le service.\n");
|
||||
return -1;
|
||||
@@ -548,21 +548,21 @@ int main (int argc, char *argv[]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Ici connexion acceptée */
|
||||
printlog (LOG_NOTIFY, "Connexion acceptée...\n");
|
||||
/* Ici connexion acceptee */
|
||||
printlog (LOG_NOTIFY, "Connexion acceptee...\n");
|
||||
|
||||
/* Lancement d'une activité de traitement */
|
||||
/* Lancement d'une activite de traitement */
|
||||
if (pthread_create (&pthread_id, NULL/*pthread_attr_default*/,
|
||||
(void *) thread_service,
|
||||
(void *) &socket_service) == -1) {
|
||||
printlog (LOG_ERROR, "Erreur création thread de service.\n");
|
||||
printlog (LOG_ERROR, "Erreur creation thread de service.\n");
|
||||
close (socket_service);
|
||||
}
|
||||
/* fflush (logfile); */
|
||||
sleep (2);
|
||||
}
|
||||
|
||||
printlog (LOG_NOTIFY, "Arrêt du serveur demandé.\n");
|
||||
printlog (LOG_NOTIFY, "Arret du serveur demande.\n");
|
||||
/* fflush (logfile); */
|
||||
close (socket_ecoute);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user