--- rpl/src/instructions_w1.c 2013/05/28 22:09:55 1.84 +++ rpl/src/instructions_w1.c 2018/06/01 09:57:28 1.110 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.14 - Copyright (C) 1989-2013 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.29 + Copyright (C) 1989-2018 Dr. BERTRAND Joël This file is part of RPL/2. @@ -410,9 +410,9 @@ instruction_write(struct_processus *s_et integer8 recursivite; logical1 format_degenere; + logical1 format_oriente_ligne; logical1 mise_a_jour; - sqlite3_stmt *ppStmt; ssize_t ios; @@ -712,7 +712,8 @@ instruction_write(struct_processus *s_et free(chaine); - if (alsprintf(&commande, "insert or replace into data " + if (alsprintf(s_etat_processus, &commande, + "insert or replace into data " "(id, data) values (%lld, '%s')", (*((integer8 *) (*s_objet_argument_2).objet)), chaine_utf8) < 0) { @@ -762,8 +763,8 @@ instruction_write(struct_processus *s_et // Récupération de la position de la clef - if (alsprintf(&commande, "select key from control " - "where id = 1") < 0) + if (alsprintf(s_etat_processus, &commande, + "select key from control where id = 1") < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -939,8 +940,8 @@ instruction_write(struct_processus *s_et // Récupération de l'identifiant de la clef - if (alsprintf(&commande, "select id from key where key = " - "'%s'", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "select id from key where key = '%s'", clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -985,8 +986,9 @@ instruction_write(struct_processus *s_et free(commande); - if (alsprintf(&commande, "insert into key " - "(key) values ('%s')", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "insert into key (key) values ('%s')", + clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1019,8 +1021,9 @@ instruction_write(struct_processus *s_et free(commande); - if (alsprintf(&commande, "select id from key " - "where key = '%s'", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "select id from key where key = '%s'", + clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1083,8 +1086,9 @@ instruction_write(struct_processus *s_et if (mise_a_jour == d_vrai) { - if (alsprintf(&commande, "update key set key = '%s' where " - "id = %lld", clef_utf8, id) < 0) + if (alsprintf(s_etat_processus, &commande, + "update key set key = '%s' where id = %lld", + clef_utf8, id) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1119,8 +1123,8 @@ instruction_write(struct_processus *s_et // Effacement de l'enregistrement existant - if (alsprintf(&commande, "delete from data where " - "key_id = %lld", id) < 0) + if (alsprintf(s_etat_processus, &commande, + "delete from data where key_id = %lld", id) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1254,8 +1258,8 @@ instruction_write(struct_processus *s_et free(chaine); - if (alsprintf(&commande, "insert into data " - "(data, key_id, sequence) values " + if (alsprintf(s_etat_processus, &commande, + "insert into data (data, key_id, sequence) values " "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0) { (*s_etat_processus).erreur_systeme = @@ -1494,53 +1498,39 @@ instruction_write(struct_processus *s_et return; } - if ((format_chaine = conversion_majuscule((unsigned char *) - (*(*l_element_courant_format).donnee).objet)) - == NULL) + if ((format_chaine = conversion_majuscule(s_etat_processus, + (unsigned char *) (*(*l_element_courant_format) + .donnee).objet)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - if (strncmp("LENGTH*(", format_chaine, 8) != 0) + if (strcmp("LINE*(*)", format_chaine) == 0) { - free(format_chaine); - - liberation(s_etat_processus, s_objet_argument_2); - liberation(s_etat_processus, s_objet_argument_1); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return; + format_oriente_ligne = d_vrai; + format_degenere = d_vrai; } - - longueur = (integer8) strlen(format_chaine); - - if (format_chaine[longueur - 1] != ')') + else { - free(format_chaine); - - liberation(s_etat_processus, s_objet_argument_2); - liberation(s_etat_processus, s_objet_argument_1); + format_oriente_ligne = d_faux; + + if (strncmp("LENGTH*(", format_chaine, 8) != 0) + { + free(format_chaine); - (*s_etat_processus).erreur_execution = - d_ex_erreur_format_fichier; - return; - } + liberation(s_etat_processus, s_objet_argument_2); + liberation(s_etat_processus, s_objet_argument_1); - format_chaine[longueur] = d_code_fin_chaine; + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return; + } - if (format_chaine[8] == '*') - { - format_degenere = d_vrai; - } - else - { - // Détermination de la longueur - format_degenere = d_faux; + longueur = (integer8) strlen(format_chaine); - if (sscanf(&(format_chaine[8]), "%lld", &longueur) != 1) + if (format_chaine[longueur - 1] != ')') { free(format_chaine); @@ -1551,6 +1541,33 @@ instruction_write(struct_processus *s_et d_ex_erreur_format_fichier; return; } + + format_chaine[longueur] = d_code_fin_chaine; + + if (format_chaine[8] == '*') + { + format_degenere = d_vrai; + } + else + { + // Détermination de la longueur + format_degenere = d_faux; + + if (sscanf(&(format_chaine[8]), "%lld", &longueur) + != 1) + { + free(format_chaine); + + liberation(s_etat_processus, + s_objet_argument_2); + liberation(s_etat_processus, + s_objet_argument_1); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_format_fichier; + return; + } + } } free(format_chaine); @@ -1592,6 +1609,17 @@ instruction_write(struct_processus *s_et free(chaine); + if (format_oriente_ligne == d_vrai) + { + if (fwrite("\n", 1, 1, (*descripteur).descripteur_c) + != 1) + { + (*s_etat_processus).erreur_systeme = + d_es_erreur_fichier; + return; + } + } + l_element_courant = (*l_element_courant).suivant; l_element_courant_format = (*l_element_courant_format) .suivant; @@ -2211,8 +2239,8 @@ instruction_wflock(struct_processus *s_e do { - if ((chaine = conversion_majuscule((unsigned char *) - (*s_objet_argument_1).objet)) == NULL) + if ((chaine = conversion_majuscule(s_etat_processus, + (unsigned char *) (*s_objet_argument_1).objet)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -2426,7 +2454,8 @@ instruction_wfproc(struct_processus *s_e } } - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2491,7 +2520,8 @@ instruction_wfproc(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2516,7 +2546,7 @@ instruction_wfproc(struct_processus *s_e { if (envoi_signal_processus((*(*((struct_processus_fils *) (*(*l_element_courant).donnee).objet)).thread).pid, - rpl_signull) != 0) + rpl_signull, d_faux) != 0) { drapeau_fin = d_vrai; } @@ -2574,7 +2604,8 @@ instruction_wfproc(struct_processus *s_e if (pthread_mutex_lock(&((*s_etat_processus) .mutex_interruptions)) != 0) { - pthread_mutex_unlock(&((*s_etat_processus).mutex)); + pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)); if ((*s_etat_processus).profilage == d_vrai) { @@ -2595,7 +2626,8 @@ instruction_wfproc(struct_processus *s_e if (pthread_mutex_unlock(&((*s_etat_processus) .mutex_interruptions)) != 0) { - pthread_mutex_unlock(&((*s_etat_processus).mutex)); + pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)); if ((*s_etat_processus).profilage == d_vrai) { @@ -2607,7 +2639,8 @@ instruction_wfproc(struct_processus *s_e return; } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2658,7 +2691,8 @@ instruction_wfproc(struct_processus *s_e scrutation_injection(s_etat_processus); - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2680,7 +2714,8 @@ instruction_wfproc(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2783,7 +2818,8 @@ instruction_wfdata(struct_processus *s_e } } - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2843,7 +2879,8 @@ instruction_wfdata(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2886,7 +2923,8 @@ instruction_wfdata(struct_processus *s_e return; } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2966,7 +3004,8 @@ instruction_wfdata(struct_processus *s_e return; } - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2993,7 +3032,8 @@ instruction_wfdata(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3025,6 +3065,121 @@ instruction_wfdata(struct_processus *s_e ================================================================================ */ +static inline logical1 +options_sockets(struct_processus *s_etat_processus, struct_socket *s_socket) +{ + int drapeau; + + if (((*s_socket).options & (1 << d_BROADCAST)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_BROADCAST, &drapeau, + sizeof(drapeau)) != 0) + { + return(d_erreur); + } + } + + if (((*s_socket).options & (1 << d_DONT_ROUTE)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_DONTROUTE, &drapeau, + sizeof(drapeau)) != 0) + { + return(d_erreur); + } + } + + if (((*s_socket).options & (1 << d_KEEP_ALIVE)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_KEEPALIVE, &drapeau, + sizeof(drapeau)) != 0) + { + return(d_erreur); + } + } + +# ifdef SO_PRIORITY + if (((*s_socket).options & (1 << d_PRIORITY)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_PRIORITY, + &((*s_socket).priorite), sizeof((*s_socket).priorite)) != 0) + { + return(d_erreur); + } + } +# endif + + // Les deux options suivantes ne peuvent être positionnées simultanément. + + if (((*s_socket).options & (1 << d_RECEIVE_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUF, + &((*s_socket).buffer_reception), + sizeof((*s_socket).buffer_reception)) != 0) + { + return(d_erreur); + } + } + +# ifdef SO_RCVBUFFORCE + if (((*s_socket).options & (1 << d_FORCE_RECEIVE_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUFFORCE, + &((*s_socket).buffer_reception), + sizeof((*s_socket).buffer_reception)) != 0) + { + return(d_erreur); + } + } +# endif + + // Même remarque + + if (((*s_socket).options & (1 << d_SEND_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUF, + &((*s_socket).buffer_emission), + sizeof((*s_socket).buffer_emission)) != 0) + { + return(d_erreur); + } + } + +# ifdef SO_SNDBUFFORCE + if (((*s_socket).options & (1 << d_FORCE_SEND_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUFFORCE, + &((*s_socket).buffer_emission), + sizeof((*s_socket).buffer_emission)) != 0) + { + return(d_erreur); + } + } +# endif + + if (((*s_socket).options & (1 << d_RECEIVING_TIMEOUT)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVTIMEO, + &((*s_socket).timeout_emission), + sizeof((*s_socket).timeout_emission)) != 0) + { + return(d_erreur); + } + } + + if (((*s_socket).options & (1 << d_SENDING_TIMEOUT)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDTIMEO, + &((*s_socket).timeout_emission), + sizeof((*s_socket).timeout_emission)) != 0) + { + return(d_erreur); + } + } + + return(d_absence_erreur);; +} + + void instruction_wfsock(struct_processus *s_etat_processus) { @@ -3210,12 +3365,12 @@ instruction_wfsock(struct_processus *s_e { drapeau = d_vrai; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) -# else +# else if (sem_post((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3230,11 +3385,11 @@ instruction_wfsock(struct_processus *s_e erreur = errno; # ifndef SEMAPHORES_NOMMES - while(sem_wait(&((*s_etat_processus) - .semaphore_fork)) != 0) + while(sem_wait(&((*s_etat_processus) + .semaphore_fork)) != 0) # else - while(sem_wait((*s_etat_processus).semaphore_fork) - != 0) + while(sem_wait((*s_etat_processus).semaphore_fork) + != 0) # endif { if (errno != EINTR) @@ -3268,13 +3423,13 @@ instruction_wfsock(struct_processus *s_e } else { -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3283,6 +3438,17 @@ instruction_wfsock(struct_processus *s_e return; } } + + if (options_sockets(s_etat_processus, + (*s_objet_resultat).objet) != d_absence_erreur) + { + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_resultat); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return; + } } } while(drapeau == d_faux); @@ -3313,12 +3479,12 @@ instruction_wfsock(struct_processus *s_e { drapeau = d_vrai; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) -# else +# else if (sem_post((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3331,13 +3497,13 @@ instruction_wfsock(struct_processus *s_e { erreur = errno; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3370,13 +3536,13 @@ instruction_wfsock(struct_processus *s_e } else { -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3385,6 +3551,17 @@ instruction_wfsock(struct_processus *s_e return; } } + + if (options_sockets(s_etat_processus, + (*s_objet_resultat).objet) != d_absence_erreur) + { + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_resultat); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return; + } } } while(drapeau == d_faux); @@ -3435,12 +3612,12 @@ instruction_wfsock(struct_processus *s_e { drapeau = d_vrai; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) -# else +# else if (sem_post((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3453,13 +3630,13 @@ instruction_wfsock(struct_processus *s_e { erreur = errno; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3492,13 +3669,13 @@ instruction_wfsock(struct_processus *s_e } else { -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3507,6 +3684,17 @@ instruction_wfsock(struct_processus *s_e return; } } + + if (options_sockets(s_etat_processus, + (*s_objet_resultat).objet) != d_absence_erreur) + { + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_resultat); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return; + } } } while(drapeau == d_faux); }