Annotation of rpl/src/instructions_o1.c, revision 1.98

1.1       bertrand    1: /*
                      2: ================================================================================
1.98    ! bertrand    3:   RPL/2 (R) version 4.1.31
1.97      bertrand    4:   Copyright (C) 1989-2019 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.17      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'oct'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_oct(struct_processus *s_etat_processus)
                     40: {
                     41:    (*s_etat_processus).erreur_execution = d_ex;
                     42: 
                     43:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     44:    {
                     45:        printf("\n  OCT ");
                     46: 
                     47:        if ((*s_etat_processus).langue == 'F')
                     48:        {
                     49:            printf("(base octale)\n\n");
                     50:            printf("  Aucun argument\n");
                     51:        }
                     52:        else
                     53:        {
                     54:            printf("(octal base)\n\n");
                     55:            printf("  No argument\n");
                     56:        }
                     57: 
                     58:        return;
                     59:    }
                     60:    else if ((*s_etat_processus).test_instruction == 'Y')
                     61:    {
                     62:        (*s_etat_processus).nombre_arguments = -1;
                     63:        return;
                     64:    }
                     65: 
                     66:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                     67:    {
                     68:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                     69:        {
                     70:            return;
                     71:        }
                     72:    }
                     73: 
                     74:    sf(s_etat_processus, 43);
                     75:    cf(s_etat_processus, 44);
                     76: 
                     77:    return;
                     78: }
                     79: 
                     80: 
                     81: /*
                     82: ================================================================================
                     83:   Fonction 'over'
                     84: ================================================================================
                     85:   Entrées :
                     86: --------------------------------------------------------------------------------
                     87:   Sorties :
                     88: --------------------------------------------------------------------------------
                     89:   Effets de bord : néant
                     90: ================================================================================
                     91: */
                     92: 
                     93: void
                     94: instruction_over(struct_processus *s_etat_processus)
                     95: {
                     96:    struct_objet                        *s_objet;
                     97: 
                     98:    (*s_etat_processus).erreur_execution = d_ex;
                     99: 
                    100:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    101:    {
                    102:        printf("\n  OVER ");
                    103: 
                    104:        if ((*s_etat_processus).langue == 'F')
                    105:        {
                    106:            printf("(duplication de l'objet de niveau 2)\n\n");
                    107:        }
                    108:        else
                    109:        {
                    110:            printf("(duplication of level 2 object)\n\n");
                    111:        }
                    112: 
                    113:        printf("    2: %s, %s, %s, %s, %s, %s,\n"
                    114:                "       %s, %s, %s, %s, %s,\n"
                    115:                "       %s, %s, %s, %s, %s,\n"
                    116:                "       %s, %s, %s, %s,\n"
1.95      bertrand  117:                "       %s, %s, %s\n",
1.1       bertrand  118:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    119:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
1.95      bertrand  120:                d_SQL, d_SLB, d_PRC, d_MTX, d_REC);
1.1       bertrand  121:        printf("    1: %s, %s, %s, %s, %s, %s,\n"
                    122:                "       %s, %s, %s, %s, %s,\n"
                    123:                "       %s, %s, %s, %s, %s,\n"
                    124:                "       %s, %s, %s, %s,\n"
1.95      bertrand  125:                "       %s, %s, %s\n",
1.1       bertrand  126:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    127:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
1.95      bertrand  128:                d_SQL, d_SLB, d_PRC, d_MTX, d_REC);
1.1       bertrand  129:        printf("->  3: %s, %s, %s, %s, %s, %s,\n"
                    130:                "       %s, %s, %s, %s, %s,\n"
                    131:                "       %s, %s, %s, %s, %s,\n"
                    132:                "       %s, %s, %s, %s,\n"
1.95      bertrand  133:                "       %s, %s, %s\n",
1.1       bertrand  134:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    135:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
1.95      bertrand  136:                d_SQL, d_SLB, d_PRC, d_MTX, d_REC);
1.1       bertrand  137:        printf("    ...\n");
                    138:        printf("    1: %s, %s, %s, %s, %s, %s,\n"
                    139:                "       %s, %s, %s, %s, %s,\n"
                    140:                "       %s, %s, %s, %s, %s,\n"
                    141:                "       %s, %s, %s, %s,\n"
1.95      bertrand  142:                "       %s, %s, %s\n",
1.1       bertrand  143:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    144:                d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
1.95      bertrand  145:                d_SQL, d_SLB, d_PRC, d_MTX, d_REC);
1.1       bertrand  146: 
                    147:        return;
                    148:    }
                    149:    else if ((*s_etat_processus).test_instruction == 'Y')
                    150:    {
                    151:        (*s_etat_processus).nombre_arguments = -1;
                    152:        return;
                    153:    }
                    154: 
                    155:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    156:    {
                    157:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    158:        {
                    159:            return;
                    160:        }
                    161:    }
                    162: 
                    163:    if ((*s_etat_processus).hauteur_pile_operationnelle < 2)
                    164:    {
                    165:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    166:        return;
                    167:    }
                    168: 
                    169:    s_objet = copie_objet(s_etat_processus,
                    170:            (*(*(*s_etat_processus).l_base_pile).suivant).donnee, 'P');
                    171: 
                    172:    if (s_objet == NULL)
                    173:    {
                    174:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    175:        return;
                    176:    }
                    177: 
                    178:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    179:            s_objet) == d_erreur)
                    180:    {
                    181:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    182:        return;
                    183:    }
                    184: 
                    185:    return;
                    186: }
                    187: 
                    188: 
                    189: /*
                    190: ================================================================================
                    191:   Fonction 'or'
                    192: ================================================================================
                    193:   Entrées : pointeur sur une structure struct_processus
                    194: --------------------------------------------------------------------------------
                    195:   Sorties :
                    196: --------------------------------------------------------------------------------
                    197:   Effets de bord : néant
                    198: ================================================================================
                    199: */
                    200: 
                    201: void
                    202: instruction_or(struct_processus *s_etat_processus)
                    203: {
                    204:    struct_liste_chainee        *l_element_courant;
                    205:    struct_liste_chainee        *l_element_precedent;
                    206: 
                    207:    struct_objet                *s_copie_argument_1;
                    208:    struct_objet                *s_copie_argument_2;
                    209:    struct_objet                *s_objet_argument_1;
                    210:    struct_objet                *s_objet_argument_2;
                    211:    struct_objet                *s_objet_resultat;
                    212: 
1.66      bertrand  213:    integer8                    nombre_elements;
1.1       bertrand  214: 
                    215:    (*s_etat_processus).erreur_execution = d_ex;
                    216: 
                    217:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    218:    {
                    219:        printf("\n  OR ");
                    220: 
                    221:        if ((*s_etat_processus).langue == 'F')
                    222:        {
                    223:            printf("(opérateur ou)\n\n");
                    224:        }
                    225:        else
                    226:        {
                    227:            printf("(or operator)\n\n");
                    228:        }
                    229: 
                    230:        printf("    2: %s, %s\n", d_INT, d_REL);
                    231:        printf("    1: %s, %s\n", d_INT, d_REL);
                    232:        printf("->  1: %s\n\n", d_INT);
                    233: 
                    234:        printf("    2: %s\n", d_BIN);
                    235:        printf("    1: %s\n", d_BIN);
                    236:        printf("->  1: %s\n\n", d_BIN);
                    237: 
                    238:        printf("    2: %s\n", d_NOM);
                    239:        printf("    1: %s, %s, %s, %s\n", d_NOM, d_ALG, d_INT, d_REL);
                    240:        printf("->  1: %s\n\n", d_ALG);
                    241: 
                    242:        printf("    2: %s, %s, %s, %s\n", d_NOM, d_ALG, d_INT, d_REL);
                    243:        printf("    1: %s\n", d_NOM);
                    244:        printf("->  1: %s\n\n", d_ALG);
                    245: 
                    246:        printf("    2: %s\n", d_ALG);
                    247:        printf("    1: %s\n", d_ALG);
                    248:        printf("->  1: %s\n\n", d_ALG);
                    249: 
                    250:        printf("    2: %s\n", d_RPN);
                    251:        printf("    1: %s\n", d_RPN);
                    252:        printf("->  1: %s\n", d_RPN);
                    253: 
                    254:        return;
                    255:    }
                    256:    else if ((*s_etat_processus).test_instruction == 'Y')
                    257:    {
                    258:        (*s_etat_processus).nombre_arguments = 0;
                    259:        return;
                    260:    }
                    261:    
                    262:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    263:    {
                    264:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    265:        {
                    266:            return;
                    267:        }
                    268:    }
                    269: 
                    270:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    271:            &s_objet_argument_1) == d_erreur)
                    272:    {
                    273:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    274:        return;
                    275:    }
                    276: 
                    277:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    278:            &s_objet_argument_2) == d_erreur)
                    279:    {
                    280:        liberation(s_etat_processus, s_objet_argument_1);
                    281: 
                    282:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    283:        return;
                    284:    }
                    285: 
                    286: /*
                    287: --------------------------------------------------------------------------------
                    288:   OR logique
                    289: --------------------------------------------------------------------------------
                    290: */
                    291: 
                    292:    if ((((*s_objet_argument_1).type == INT) ||
                    293:            ((*s_objet_argument_1).type == REL)) &&
                    294:            (((*s_objet_argument_2).type == INT) ||
                    295:            ((*s_objet_argument_2).type == REL)))
                    296:    {
                    297:        if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
                    298:        {
                    299:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    300:            return;
                    301:        }
                    302: 
                    303:        if ((*s_objet_argument_1).type == INT)
                    304:        {
                    305:            if ((*s_objet_argument_2).type == INT)
                    306:            {
                    307:                if (((*((integer8 *) (*s_objet_argument_1).objet)) != 0) ||
                    308:                        ((*((integer8 *) (*s_objet_argument_2).objet)) != 0))
                    309:                {
                    310:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    311:                }
                    312:                else
                    313:                {
                    314:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    315:                }
                    316:            }
                    317:            else
                    318:            {
                    319:                if (((*((integer8 *) (*s_objet_argument_1).objet)) != 0) ||
                    320:                        ((*((real8 *) (*s_objet_argument_2).objet)) != 0))
                    321:                {
                    322:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    323:                }
                    324:                else
                    325:                {
                    326:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    327:                }
                    328:            }
                    329:        }
                    330:        else
                    331:        {
                    332:            if ((*s_objet_argument_2).type == INT)
                    333:            {
                    334:                if (((*((real8 *) (*s_objet_argument_1).objet)) != 0) ||
                    335:                        ((*((integer8 *) (*s_objet_argument_2).objet)) != 0))
                    336:                {
                    337:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    338:                }
                    339:                else
                    340:                {
                    341:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    342:                }
                    343:            }
                    344:            else
                    345:            {
                    346:                if (((*((real8 *) (*s_objet_argument_1).objet)) != 0) ||
                    347:                        ((*((real8 *) (*s_objet_argument_2).objet)) != 0))
                    348:                {
                    349:                    (*((integer8 *) (*s_objet_resultat).objet)) = -1;
                    350:                }
                    351:                else
                    352:                {
                    353:                    (*((integer8 *) (*s_objet_resultat).objet)) = 0;
                    354:                }
                    355:            }
                    356:        }
                    357:    }
                    358: 
                    359: /*
                    360: --------------------------------------------------------------------------------
                    361:   OR binaire
                    362: --------------------------------------------------------------------------------
                    363: */
                    364: 
                    365:    else if (((*s_objet_argument_1).type == BIN) &&
                    366:            ((*s_objet_argument_2).type == BIN))
                    367:    {
                    368:        if ((s_objet_resultat = allocation(s_etat_processus, BIN)) == NULL)
                    369:        {
                    370:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    371:            return;
                    372:        }
                    373: 
                    374:        (*((logical8 *) (*s_objet_resultat).objet)) = 
                    375:                (*((logical8 *) (*s_objet_argument_1).objet)) |
                    376:                (*((logical8 *) (*s_objet_argument_2).objet));
                    377:    }
                    378: 
                    379: /*
                    380: --------------------------------------------------------------------------------
                    381:    OR entre des arguments complexes
                    382: --------------------------------------------------------------------------------
                    383: */
                    384: 
                    385:    /*
                    386:     * Nom ou valeur numérique / Nom ou valeur numérique
                    387:     */
                    388: 
                    389:    else if ((((*s_objet_argument_1).type == NOM) &&
                    390:            (((*s_objet_argument_2).type == NOM) ||
                    391:            ((*s_objet_argument_2).type == INT) ||
                    392:            ((*s_objet_argument_2).type == REL))) ||
                    393:            (((*s_objet_argument_2).type == NOM) &&
                    394:            (((*s_objet_argument_1).type == INT) ||
                    395:            ((*s_objet_argument_1).type == REL))))
                    396:    {
                    397:        if ((s_objet_resultat = allocation(s_etat_processus, ALG)) == NULL)
                    398:        {
                    399:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    400:            return;
                    401:        }
                    402: 
                    403:        if (((*s_objet_resultat).objet =
                    404:                allocation_maillon(s_etat_processus)) == NULL)
                    405:        {
                    406:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    407:            return;
                    408:        }
                    409: 
                    410:        l_element_courant = (*s_objet_resultat).objet;
                    411: 
                    412:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    413:                == NULL)
                    414:        {
                    415:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    416:            return;
                    417:        }
                    418: 
                    419:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    420:                .nombre_arguments = 0;
                    421:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    422:                .fonction = instruction_vers_niveau_superieur;
                    423: 
                    424:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    425:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    426:        {
                    427:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    428:            return;
                    429:        }
                    430: 
                    431:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    432:                .nom_fonction, "<<");
                    433: 
                    434:        if (((*l_element_courant).suivant =
                    435:                allocation_maillon(s_etat_processus)) == NULL)
                    436:        {
                    437:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    438:            return;
                    439:        }
                    440: 
                    441:        l_element_courant = (*l_element_courant).suivant;
                    442:        (*l_element_courant).donnee = s_objet_argument_2;
                    443: 
                    444:        if (((*l_element_courant).suivant =
                    445:                allocation_maillon(s_etat_processus)) == NULL)
                    446:        {
                    447:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    448:            return;
                    449:        }
                    450: 
                    451:        l_element_courant = (*l_element_courant).suivant;
                    452:        (*l_element_courant).donnee = s_objet_argument_1;
                    453: 
                    454:        if (((*l_element_courant).suivant =
                    455:                allocation_maillon(s_etat_processus)) == NULL)
                    456:        {
                    457:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    458:            return;
                    459:        }
                    460: 
                    461:        l_element_courant = (*l_element_courant).suivant;
                    462: 
                    463:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    464:                == NULL)
                    465:        {
                    466:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    467:            return;
                    468:        }
                    469: 
                    470:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    471:                .nombre_arguments = 0;
                    472:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    473:                .fonction = instruction_or;
                    474: 
                    475:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    476:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    477:        {
                    478:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    479:            return;
                    480:        }
                    481: 
                    482:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    483:                .nom_fonction, "OR");
                    484: 
                    485:        if (((*l_element_courant).suivant =
                    486:                allocation_maillon(s_etat_processus)) == NULL)
                    487:        {
                    488:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    489:            return;
                    490:        }
                    491: 
                    492:        l_element_courant = (*l_element_courant).suivant;
                    493: 
                    494:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    495:                == NULL)
                    496:        {
                    497:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    498:            return;
                    499:        }
                    500: 
                    501:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    502:                .nombre_arguments = 0;
                    503:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    504:                .fonction = instruction_vers_niveau_inferieur;
                    505: 
                    506:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    507:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    508:        {
                    509:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    510:            return;
                    511:        }
                    512: 
                    513:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    514:                .nom_fonction, ">>");
                    515: 
                    516:        (*l_element_courant).suivant = NULL;
                    517: 
                    518:        s_objet_argument_1 = NULL;
                    519:        s_objet_argument_2 = NULL;
                    520:    }
                    521: 
                    522:    /*
                    523:     * Nom ou valeur numérique / Expression
                    524:     */
                    525: 
                    526:    else if ((((*s_objet_argument_1).type == ALG) ||
                    527:            ((*s_objet_argument_1).type == RPN)) &&
                    528:            (((*s_objet_argument_2).type == NOM) ||
                    529:            ((*s_objet_argument_2).type == INT) ||
                    530:            ((*s_objet_argument_2).type == REL)))
                    531:    {
                    532:        nombre_elements = 0;
                    533:        l_element_courant = (struct_liste_chainee *)
                    534:                (*s_objet_argument_1).objet;
                    535: 
                    536:        while(l_element_courant != NULL)
                    537:        {
                    538:            nombre_elements++;
                    539:            l_element_courant = (*l_element_courant).suivant;
                    540:        }
                    541: 
                    542:        if (nombre_elements == 2)
                    543:        {
                    544:            liberation(s_etat_processus, s_objet_argument_1);
                    545:            liberation(s_etat_processus, s_objet_argument_2);
                    546: 
                    547:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    548:            return;
                    549:        }
                    550: 
                    551:        if ((s_objet_resultat = copie_objet(s_etat_processus,
                    552:                s_objet_argument_1, 'N')) == NULL)
                    553:        {
                    554:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    555:            return;
                    556:        }
                    557: 
                    558:        l_element_courant = (struct_liste_chainee *)
                    559:                (*s_objet_resultat).objet;
                    560:        l_element_precedent = l_element_courant;
                    561:        l_element_courant = (*l_element_courant).suivant;
                    562: 
                    563:        if (((*l_element_precedent).suivant =
                    564:                allocation_maillon(s_etat_processus)) == NULL)
                    565:        {
                    566:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    567:            return;
                    568:        }
                    569: 
                    570:        (*(*l_element_precedent).suivant).donnee = s_objet_argument_2;
                    571:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    572: 
                    573:        while((*l_element_courant).suivant != NULL)
                    574:        {
                    575:            l_element_precedent = l_element_courant;
                    576:            l_element_courant = (*l_element_courant).suivant;
                    577:        }
                    578: 
                    579:        if (((*l_element_precedent).suivant =
                    580:                allocation_maillon(s_etat_processus)) == NULL)
                    581:        {
                    582:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    583:            return;
                    584:        }
                    585: 
                    586:        if (((*(*l_element_precedent).suivant).donnee =
                    587:                allocation(s_etat_processus, FCT)) == NULL)
                    588:        {
                    589:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    590:            return;
                    591:        }
                    592: 
                    593:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    594:                .donnee).objet)).nombre_arguments = 0;
                    595:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    596:                .donnee).objet)).fonction = instruction_or;
                    597: 
                    598:        if (((*((struct_fonction *) (*(*(*l_element_precedent)
                    599:                .suivant).donnee).objet)).nom_fonction =
                    600:                malloc(3 * sizeof(unsigned char))) == NULL)
                    601:        {
                    602:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    603:            return;
                    604:        }
                    605: 
                    606:        strcpy((*((struct_fonction *) (*(*(*l_element_precedent)
                    607:                .suivant).donnee).objet)).nom_fonction, "OR");
                    608: 
                    609:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    610: 
                    611:        s_objet_argument_2 = NULL;
                    612:    }
                    613: 
                    614:    /*
                    615:     * Expression / Nom ou valeur numérique
                    616:     */
                    617: 
                    618:    else if ((((*s_objet_argument_1).type == NOM) ||
                    619:            ((*s_objet_argument_1).type == INT) ||
                    620:            ((*s_objet_argument_1).type == REL)) &&
                    621:            (((*s_objet_argument_2).type == ALG) ||
                    622:            ((*s_objet_argument_2).type == RPN)))
                    623:    {
                    624:        nombre_elements = 0;
                    625:        l_element_courant = (struct_liste_chainee *)
                    626:                (*s_objet_argument_2).objet;
                    627: 
                    628:        while(l_element_courant != NULL)
                    629:        {
                    630:            nombre_elements++;
                    631:            l_element_courant = (*l_element_courant).suivant;
                    632:        }
                    633: 
                    634:        if (nombre_elements == 2)
                    635:        {
                    636:            liberation(s_etat_processus, s_objet_argument_1);
                    637:            liberation(s_etat_processus, s_objet_argument_2);
                    638: 
                    639:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    640:            return;
                    641:        }
                    642: 
                    643:        if ((s_objet_resultat = copie_objet(s_etat_processus,
                    644:                s_objet_argument_2, 'N')) == NULL)
                    645:        {
                    646:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    647:            return;
                    648:        }
                    649: 
                    650:        l_element_courant = (struct_liste_chainee *)
                    651:                (*s_objet_resultat).objet;
                    652:        l_element_precedent = l_element_courant;
                    653: 
                    654:        while((*l_element_courant).suivant != NULL)
                    655:        {
                    656:            l_element_precedent = l_element_courant;
                    657:            l_element_courant = (*l_element_courant).suivant;
                    658:        }
                    659: 
                    660:        if (((*l_element_precedent).suivant =
                    661:                allocation_maillon(s_etat_processus)) == NULL)
                    662:        {
                    663:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    664:            return;
                    665:        }
                    666: 
                    667:        (*(*l_element_precedent).suivant).donnee = s_objet_argument_1;
                    668:        l_element_precedent = (*l_element_precedent).suivant;
                    669: 
                    670:        if (((*l_element_precedent).suivant =
                    671:                allocation_maillon(s_etat_processus)) == NULL)
                    672:        {
                    673:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    674:            return;
                    675:        }
                    676: 
                    677:        if (((*(*l_element_precedent).suivant).donnee =
                    678:                allocation(s_etat_processus, FCT)) == NULL)
                    679:        {
                    680:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    681:            return;
                    682:        }
                    683: 
                    684:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    685:                .donnee).objet)).nombre_arguments = 0;
                    686:        (*((struct_fonction *) (*(*(*l_element_precedent).suivant)
                    687:                .donnee).objet)).fonction = instruction_or;
                    688: 
                    689:        if (((*((struct_fonction *) (*(*(*l_element_precedent)
                    690:                .suivant).donnee).objet)).nom_fonction =
                    691:                malloc(3 * sizeof(unsigned char))) == NULL)
                    692:        {
                    693:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    694:            return;
                    695:        }
                    696: 
                    697:        strcpy((*((struct_fonction *) (*(*(*l_element_precedent)
                    698:                .suivant).donnee).objet)).nom_fonction, "OR");
                    699: 
                    700:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    701: 
                    702:        s_objet_argument_1 = NULL;
                    703:    }
                    704: 
                    705:    /*
                    706:     * Expression / Expression
                    707:     */
                    708: 
                    709:    else if ((((*s_objet_argument_1).type == ALG) &&
                    710:            ((*s_objet_argument_2).type == ALG)) ||
                    711:            (((*s_objet_argument_1).type == RPN) &&
                    712:            ((*s_objet_argument_2).type == RPN)))
                    713:    {
                    714:        nombre_elements = 0;
                    715:        l_element_courant = (struct_liste_chainee *)
                    716:                (*s_objet_argument_1).objet;
                    717: 
                    718:        while(l_element_courant != NULL)
                    719:        {
                    720:            nombre_elements++;
                    721:            l_element_courant = (*l_element_courant).suivant;
                    722:        }
                    723: 
                    724:        if (nombre_elements == 2)
                    725:        {
                    726:            liberation(s_etat_processus, s_objet_argument_1);
                    727:            liberation(s_etat_processus, s_objet_argument_2);
                    728: 
                    729:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    730:            return;
                    731:        }
                    732: 
                    733:        nombre_elements = 0;
                    734:        l_element_courant = (struct_liste_chainee *)
                    735:                (*s_objet_argument_2).objet;
                    736: 
                    737:        while(l_element_courant != NULL)
                    738:        {
                    739:            nombre_elements++;
                    740:            l_element_courant = (*l_element_courant).suivant;
                    741:        }
                    742: 
                    743:        if (nombre_elements == 2)
                    744:        {
                    745:            liberation(s_etat_processus, s_objet_argument_1);
                    746:            liberation(s_etat_processus, s_objet_argument_2);
                    747: 
                    748:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    749:            return;
                    750:        }
                    751: 
                    752:        if ((s_copie_argument_1 = copie_objet(s_etat_processus,
                    753:                s_objet_argument_1, 'N')) == NULL)
                    754:        {
                    755:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    756:            return;
                    757:        }
                    758: 
                    759:        if ((s_copie_argument_2 = copie_objet(s_etat_processus,
                    760:                s_objet_argument_2, 'N')) == NULL)
                    761:        {
                    762:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    763:            return;
                    764:        }
                    765: 
                    766:        l_element_courant = (struct_liste_chainee *)
                    767:                (*s_copie_argument_1).objet;
                    768:        (*s_copie_argument_1).objet = (void *) (*((struct_liste_chainee *)
                    769:                (*s_copie_argument_1).objet)).suivant;
                    770: 
                    771:        liberation(s_etat_processus, (*l_element_courant).donnee);
                    772:        free(l_element_courant);
                    773: 
                    774:        l_element_courant = (struct_liste_chainee *)
                    775:                (*s_copie_argument_2).objet;
                    776:        l_element_precedent = l_element_courant;
                    777:        s_objet_resultat = s_copie_argument_2;
                    778: 
                    779:        while((*l_element_courant).suivant != NULL)
                    780:        {
                    781:            l_element_precedent = l_element_courant;
                    782:            l_element_courant = (*l_element_courant).suivant;
                    783:        }
                    784: 
                    785:        liberation(s_etat_processus, (*l_element_courant).donnee);
                    786:        free(l_element_courant);
                    787: 
                    788:        (*l_element_precedent).suivant = (struct_liste_chainee *)
                    789:                (*s_copie_argument_1).objet;
                    790:        free(s_copie_argument_1);
                    791: 
                    792:        l_element_courant = (*l_element_precedent).suivant;
                    793:        while((*l_element_courant).suivant != NULL)
                    794:        {
                    795:            l_element_precedent = l_element_courant;
                    796:            l_element_courant = (*l_element_courant).suivant;
                    797:        }
                    798: 
                    799:        if (((*l_element_precedent).suivant =
                    800:                allocation_maillon(s_etat_processus)) == NULL)
                    801:        {
                    802:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    803:            return;
                    804:        }
                    805: 
                    806:        (*(*l_element_precedent).suivant).suivant = l_element_courant;
                    807:        l_element_courant = (*l_element_precedent).suivant;
                    808: 
                    809:        if (((*l_element_courant).donnee = allocation(s_etat_processus, FCT))
                    810:                == NULL)
                    811:        {
                    812:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    813:            return;
                    814:        }
                    815: 
                    816:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    817:                .nombre_arguments = 0;
                    818:        (*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    819:                .fonction = instruction_or;
                    820: 
                    821:        if (((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    822:                .nom_fonction = malloc(3 * sizeof(unsigned char))) == NULL)
                    823:        {
                    824:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    825:            return;
                    826:        }
                    827: 
                    828:        strcpy((*((struct_fonction *) (*(*l_element_courant).donnee).objet))
                    829:                .nom_fonction, "OR");
                    830:    }
                    831: 
                    832: /*
                    833: --------------------------------------------------------------------------------
                    834:   OR impossible
                    835: --------------------------------------------------------------------------------
                    836: */
                    837: 
                    838:    else
                    839:    {
                    840:        liberation(s_etat_processus, s_objet_argument_1);
                    841:        liberation(s_etat_processus, s_objet_argument_2);
                    842: 
                    843:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    844:        return;
                    845:    }
                    846: 
                    847:    liberation(s_etat_processus, s_objet_argument_1);
                    848:    liberation(s_etat_processus, s_objet_argument_2);
                    849: 
                    850:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    851:            s_objet_resultat) == d_erreur)
                    852:    {
                    853:        return;
                    854:    }
                    855: 
                    856:    return;
                    857: }
                    858: 
                    859: 
                    860: /*
                    861: ================================================================================
                    862:   Fonction 'open'
                    863: ================================================================================
                    864:   Entrées : pointeur sur une structure struct_processus
                    865: --------------------------------------------------------------------------------
                    866:   Sorties :
                    867: --------------------------------------------------------------------------------
                    868:   Effets de bord : néant
                    869: ================================================================================
                    870: */
                    871: 
1.82      bertrand  872: 
                    873: static inline logical1
                    874: options_socket(struct_processus *s_etat_processus,
                    875:        struct_objet *s_objet_resultat, unsigned char *options,
                    876:        unsigned char *peripherique, int *priorite,
                    877:        int *buffer_emission, int *buffer_reception,
                    878:        int *timeout_emission, int *timeout_reception)
                    879: {
                    880:    int             drapeau;
                    881: 
                    882:    /*
                    883:     * Options des sockets
                    884:     */
                    885: 
                    886:    drapeau = -1;
                    887: 
                    888: #  define WARNING(message) { \
                    889:    if ((*s_etat_processus).langue != 'F') \
                    890:        printf("+++Warning : %s unavailable on host system\n", message); \
                    891:    else \
                    892:        printf("+++Attention : %s non disponible sur le système hôte\n", \
                    893:                message); } while(0)
                    894: 
                    895:    if (options[d_BIND_TO_DEVICE] == 'Y')
                    896:    {
                    897: #      ifdef SO_BINDTODEVICE
                    898:            if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet))
                    899:                    .socket, SOL_SOCKET, SO_BINDTODEVICE, peripherique,
                    900:                    (socklen_t) strlen(peripherique)) != 0)
                    901:            {
                    902:                (*s_etat_processus).erreur_execution =
                    903:                        d_ex_erreur_parametre_fichier;
                    904:                return(d_erreur);
                    905:            }
1.84      bertrand  906: 
                    907:            (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                    908:                    ((integer8) 1) << d_BIND_TO_DEVICE;
1.82      bertrand  909: #      else
                    910:            WARNING("BIND TO DEVICE");
                    911: #      endif
                    912:    }
                    913: 
                    914:    if (options[d_BROADCAST] == 'Y')
                    915:    {
                    916:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                    917:                SOL_SOCKET, SO_BROADCAST, &drapeau, sizeof(drapeau)) != 0)
                    918:        {
                    919:            (*s_etat_processus).erreur_execution =
                    920:                    d_ex_erreur_parametre_fichier;
                    921:            return(d_erreur);
                    922:        }
1.84      bertrand  923: 
                    924:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                    925:                ((integer8) 1) << d_BROADCAST;
1.82      bertrand  926:    }
                    927: 
                    928:    if (options[d_DONT_ROUTE] == 'Y')
                    929:    {
                    930:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                    931:                SOL_SOCKET, SO_DONTROUTE, &drapeau, sizeof(drapeau)) != 0)
                    932:        {
                    933:            (*s_etat_processus).erreur_execution =
                    934:                    d_ex_erreur_parametre_fichier;
                    935:            return(d_erreur);
                    936:        }
1.84      bertrand  937: 
                    938:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                    939:                ((integer8) 1) << d_DONT_ROUTE;
1.82      bertrand  940:    }
                    941: 
                    942:    if (options[d_KEEP_ALIVE] == 'Y')
                    943:    {
                    944:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                    945:                SOL_SOCKET, SO_KEEPALIVE, &drapeau, sizeof(drapeau)) != 0)
                    946:        {
                    947:            (*s_etat_processus).erreur_execution =
                    948:                    d_ex_erreur_parametre_fichier;
                    949:            return(d_erreur);
                    950:        }
                    951:    }
                    952: 
                    953:    if (options[d_PRIORITY] == 'Y')
                    954:    {
                    955: #      ifdef SO_PRIORITY
                    956:            if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet))
                    957:                .socket, SOL_SOCKET, SO_PRIORITY, priorite,
                    958:                sizeof((*priorite))) != 0)
                    959:            {
                    960:                (*s_etat_processus).erreur_execution =
                    961:                        d_ex_erreur_parametre_fichier;
                    962:                return(d_erreur);
                    963:            }
1.84      bertrand  964: 
                    965:            (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                    966:                    ((integer8) 1) << d_PRIORITY;
                    967:            (*((struct_socket *) (*s_objet_resultat).objet)).priorite =
                    968:                    (*priorite);
1.82      bertrand  969: #      else
                    970:            WARNING("PRIORITY");
                    971: #      endif
                    972:    }
                    973: 
                    974:    if (options[d_RECEIVE_BUFFER] == 'Y')
                    975:    {
                    976:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                    977:                SOL_SOCKET, SO_RCVBUF, buffer_reception,
                    978:                sizeof((*buffer_reception))) != 0)
                    979:        {
                    980:            (*s_etat_processus).erreur_execution =
                    981:                    d_ex_erreur_parametre_fichier;
                    982:            return(d_erreur);
                    983:        }
1.84      bertrand  984: 
                    985:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                    986:                ((integer8) 1) << d_RECEIVE_BUFFER;
                    987:        (*((struct_socket *) (*s_objet_resultat).objet)).buffer_reception =
                    988:                (*buffer_reception);
1.82      bertrand  989:    }
                    990: 
                    991:    if (options[d_FORCE_RECEIVE_BUFFER] == 'Y')
                    992:    {
                    993: #      ifdef SO_RCVBUFFORCE
                    994:            if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet))
                    995:                    .socket, SOL_SOCKET, SO_RCVBUFFORCE,
                    996:                    buffer_reception, sizeof((*buffer_reception))) != 0)
                    997:            {
                    998:                (*s_etat_processus).erreur_execution =
                    999:                        d_ex_erreur_parametre_fichier;
                   1000:                return(d_erreur);
                   1001:            }
1.84      bertrand 1002: 
                   1003:            (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                   1004:                    ((integer8) 1) << d_FORCE_RECEIVE_BUFFER;
                   1005:            (*((struct_socket *) (*s_objet_resultat).objet)).buffer_reception =
                   1006:                    (*buffer_reception);
1.82      bertrand 1007: #      else
                   1008:            WARNING("FORCE_RECEIVE_BUFFER");
                   1009: #      endif
                   1010:    }
                   1011: 
                   1012:    if (options[d_SEND_BUFFER] == 'Y')
                   1013:    {
                   1014:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                   1015:                SOL_SOCKET, SO_SNDBUF, buffer_emission,
                   1016:                sizeof((*buffer_emission))) != 0)
                   1017:        {
                   1018:            (*s_etat_processus).erreur_execution =
                   1019:                    d_ex_erreur_parametre_fichier;
                   1020:            return(d_erreur);
                   1021:        }
1.84      bertrand 1022: 
                   1023:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                   1024:                ((integer8) 1) << d_SEND_BUFFER;
                   1025:        (*((struct_socket *) (*s_objet_resultat).objet)).buffer_emission =
                   1026:                (*buffer_emission);
1.82      bertrand 1027:    }
                   1028: 
                   1029:    if (options[d_FORCE_SEND_BUFFER] == 'Y')
                   1030:    {
                   1031: #      ifdef SO_SNDBUFFORCE
                   1032:            if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet))
                   1033:                    .socket, SOL_SOCKET, SO_SNDBUFFORCE, buffer_emission,
                   1034:                    sizeof((*buffer_emission))) != 0)
                   1035:            {
                   1036:                (*s_etat_processus).erreur_execution =
                   1037:                        d_ex_erreur_parametre_fichier;
                   1038:                return(d_erreur);
                   1039:            }
1.84      bertrand 1040: 
                   1041:            (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                   1042:                    ((integer8) 1) << d_FORCE_SEND_BUFFER;
                   1043:            (*((struct_socket *) (*s_objet_resultat).objet)).buffer_emission =
                   1044:                    (*buffer_emission);
1.82      bertrand 1045: #      else
                   1046:            WARNING("FORCE_SEND_BUFFER");
                   1047: #      endif
                   1048:    }
                   1049: 
                   1050:    if (options[d_RECEIVING_TIMEOUT] == 'Y')
                   1051:    {
                   1052:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                   1053:                SOL_SOCKET, SO_RCVTIMEO,
                   1054:                timeout_reception, sizeof((*timeout_reception))) != 0)
                   1055:        {
                   1056:            (*s_etat_processus).erreur_execution =
                   1057:                    d_ex_erreur_parametre_fichier;
                   1058:            return(d_erreur);
                   1059:        }
1.84      bertrand 1060: 
                   1061:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                   1062:                ((integer8) 1) << d_RECEIVING_TIMEOUT;
                   1063:        (*((struct_socket *) (*s_objet_resultat).objet)).timeout_reception =
                   1064:                (*timeout_reception);
1.82      bertrand 1065:    }
                   1066: 
                   1067:    if (options[d_SENDING_TIMEOUT] == 'Y')
                   1068:    {
                   1069:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                   1070:                SOL_SOCKET, SO_SNDTIMEO,
                   1071:                timeout_emission, sizeof((*timeout_emission))) != 0)
                   1072:        {
                   1073:            (*s_etat_processus).erreur_execution =
                   1074:                    d_ex_erreur_parametre_fichier;
                   1075:            return(d_erreur);
                   1076:        }
1.84      bertrand 1077: 
                   1078:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                   1079:                ((integer8) 1) << d_SENDING_TIMEOUT;
                   1080:        (*((struct_socket *) (*s_objet_resultat).objet)).timeout_emission =
                   1081:                (*timeout_emission);
1.82      bertrand 1082:    }
                   1083: 
                   1084:    if (options[d_REUSE_ADDRESS] == 'Y')
                   1085:    {
                   1086:        if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket,
                   1087:                SOL_SOCKET, SO_REUSEADDR, &drapeau, sizeof(drapeau)) != 0)
                   1088:        {
                   1089:            (*s_etat_processus).erreur_execution =
                   1090:                    d_ex_erreur_parametre_fichier;
                   1091:            return(d_erreur);
                   1092:        }
1.84      bertrand 1093: 
                   1094:        (*((struct_socket *) (*s_objet_resultat).objet)).options |=
                   1095:                ((integer8) 1) << d_REUSE_ADDRESS;
1.82      bertrand 1096:    }
                   1097: 
                   1098:    return(d_absence_erreur);
                   1099: #  undef   WARNING
                   1100: }
                   1101: 
                   1102: 
1.1       bertrand 1103: void
                   1104: instruction_open(struct_processus *s_etat_processus)
                   1105: {
                   1106:    /*
                   1107:     * Type d'ouverture :
                   1108:     *   NEW     : crée un nouveau fichier, retourne une erreur si un fichier
                   1109:     *             préexiste ;
                   1110:     *   OLD     : ouvre un fichier existant, retourne une erreur si le fichier
                   1111:     *             n'existe pas ;
                   1112:     *   REPLACE : remplace un fichier existant, retourne une erreur s'il n'y
                   1113:     *             a aucun fichier à effacer ;
                   1114:     *   UNKNOWN : ouvre un fichier existant ou crée un nouveau fichier ;
                   1115:     *   SCRATCH : crée un fichier temporaire automatiquement effacé lors
                   1116:     *             de sa fermeture (protection automatique 'readwrite');
                   1117:     *
                   1118:     * Type d'accès :
                   1119:     *   SEQUENTIAL : accès séquentiel ;
                   1120:     *   DIRECT     : accès direct ;
                   1121:     *   KEYED      : accès indexé.
                   1122:     *
                   1123:     * Protection :
                   1124:     *   READONLY  : lecture seule ;
                   1125:     *   WRITEONLY : écriture seule ;
                   1126:     *   READWRITE : lecture et écriture autorisées.
                   1127:     *
                   1128:     * Format :
                   1129:     *   FORMATTED   : fichier texte ;
                   1130:     *   UNFORMATTED : fichier binaire.
1.27      bertrand 1131:     *   FLOW        : chaîne de caractères sans format (en tant qu'objet
                   1132:     *                 binaire comme "\x00avz\xFD")
1.1       bertrand 1133:     */
                   1134: 
                   1135:    file                        *descripteur;
                   1136: 
                   1137:    int                         buffer_emission;
                   1138:    int                         buffer_reception;
                   1139:    int                         priorite;
1.67      bertrand 1140:    int                         prochain_descripteur;
1.1       bertrand 1141:    int                         protocole_numerique;
                   1142:    int                         timeout_emission;
                   1143:    int                         timeout_reception;
                   1144:    int                         type;
                   1145: 
                   1146:    integer8                    adresse[16];
                   1147:    integer8                    nombre_maximal_connexions;
                   1148:    integer8                    port;
                   1149:    integer8                    position_clef;
                   1150: 
                   1151:    logical1                    erreur;
                   1152:    logical1                    existence;
1.48      bertrand 1153:    logical1                    negation;
1.1       bertrand 1154:    logical1                    ouverture;
                   1155:    logical1                    presence_port;
                   1156: 
1.6       bertrand 1157:    sqlite3                     *sqlite;
                   1158: 
1.1       bertrand 1159:    struct_liste_chainee        *l_element_courant;
                   1160:    struct_liste_chainee        *l_element_courant_sous_objet;
1.46      bertrand 1161:    struct_liste_chainee        *parametre_courant;
1.1       bertrand 1162: 
                   1163:    struct flock                lock;
                   1164: 
                   1165:    struct addrinfo             *resolution;
                   1166:    struct addrinfo             *resolution_courante;
                   1167: 
                   1168:    struct protoent             *s_protocole;
                   1169: 
                   1170:    struct sockaddr_un          socket_unix;
                   1171:    struct sockaddr_in          socket_ipv4;
1.17      bertrand 1172: #  ifdef IPV6
1.1       bertrand 1173:    struct sockaddr_in6         socket_ipv6;
1.17      bertrand 1174: #  endif
1.1       bertrand 1175: 
                   1176:    struct_objet                *s_objet_argument;
                   1177:    struct_objet                *s_objet_resultat;
1.45      bertrand 1178:    struct_objet                *s_parametres_tty;
                   1179: 
                   1180:    struct termios              tc;
1.1       bertrand 1181: 
                   1182:    uint32_t                    adresse_ipv4;
                   1183: 
                   1184:    unsigned char               *argument_majuscule;
                   1185:    unsigned char               *chaine_descripteurs;
                   1186:    unsigned char               format;
                   1187:    unsigned char               *hote;
                   1188:    unsigned char               *nom;
                   1189:    unsigned char               *nom_temporaire;
                   1190:    unsigned char               options[12];
1.46      bertrand 1191:    unsigned char               *parametre_courant_majuscule;
1.1       bertrand 1192:    unsigned char               *peripherique;
                   1193:    unsigned char               *pointeur;
1.46      bertrand 1194:    unsigned char               *position;
1.1       bertrand 1195:    unsigned char               protection;
                   1196:    unsigned char               protocole[16 + 1];
                   1197:    unsigned char               *protocole_socket;
                   1198:    unsigned char               type_acces;
                   1199:    unsigned char               type_adresse;
                   1200:    unsigned char               type_arguments;
                   1201:    unsigned char               type_domaine;
                   1202:    unsigned char               type_ouverture;
                   1203:    unsigned char               type_socket;
                   1204: 
                   1205:    unsigned long               i;
                   1206:    unsigned long               nombre_elements;
                   1207:    unsigned long               unite;
                   1208: 
                   1209:    /*
                   1210:     * Argument : { "ouverture" "accès" "format" [ { "nom" } 'protection' ] }
                   1211:     */
                   1212: 
                   1213:    (*s_etat_processus).erreur_execution = d_ex;
                   1214: 
                   1215:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1216:    {
                   1217:        printf("\n  OPEN ");
                   1218: 
                   1219:        if ((*s_etat_processus).langue == 'F')
                   1220:        {
                   1221:            printf("(ouverture d'un fichier, d'une socket ou d'un sémaphore)"
                   1222:                    "\n\n");
                   1223:        }
                   1224:        else
                   1225:        {
                   1226:            printf("(open file, socket or semaphore)\n\n");
                   1227:        }
                   1228: 
                   1229:        printf("    1: %s\n", d_LST);
                   1230:        printf("->  1: %s, %s\n\n", d_FCH, d_SCK);
                   1231: 
                   1232:        printf("    1: %s\n", d_CHN);
                   1233:        printf("->  1: %s\n\n", d_SPH);
                   1234: 
                   1235:        if ((*s_etat_processus).langue == 'F')
                   1236:        {
                   1237:            printf("  Utilisation :\n\n");
                   1238:        }
                   1239:        else
                   1240:        {
                   1241:            printf("  Usage:\n\n");
                   1242:        }
                   1243: 
                   1244:        printf("    { \"filetype\" \"access\" \"format\" { \"name\" "
                   1245:                "\"file name\" } \"protection\" } OPEN\n");
1.45      bertrand 1246:        printf("    { \"filetype\" \"access\" \"format\" { \"name\" "
                   1247:                "\"file name\" } \n"
1.72      bertrand 1248:                "           { \"stty\" \"speed,bits,parity,stop\"\n"
                   1249:                "           { \"stty parameters\" ... } } } OPEN\n");
1.1       bertrand 1250:        printf("    { \"sockettype\" { \"name\" \"local name\" } } OPEN\n");
                   1251:        printf("    { \"sockettype\" \"socketdomain\" \"protection\" } OPEN\n");
1.54      bertrand 1252:        printf("    \"/semaphore\" OPEN\n\n");
1.1       bertrand 1253: 
                   1254:        printf("    File type       : NEW/OLD/REPLACE/UNKNOWN/SCRATCH\n");
                   1255:        printf("    File access     : SEQUENTIAL/DIRECT/KEYED\n");
                   1256:        printf("    Socket type     : STREAM/DATAGRAM/RAW/"
                   1257:                "ROBUST DATAGRAM/SEQUENTIAL DATAGRAM\n");
                   1258:        printf("    Socket domain   : LOCAL/FOREIGN\n");
                   1259:        printf("    Socket protocol : IPV4/IPV6/UNIX\n");
                   1260:        printf("    Format          : FORMATTED/UNFORMATTED/FLOW\n");
                   1261:        printf("    Protection      : READONLY/WRITEONLY/READWRITE\n\n");
1.45      bertrand 1262:        printf("    Stty parameters : can be prefixed by 'NO'\n");
                   1263:        printf("            IGNBRK, BRKINT, IGNPAR, PARMRK, INPCK, ISTRIP\n");
                   1264:        printf("            INLCR, IGNCR, ICRNL, IXON, IXANY, IXOFF,\n");
                   1265:        printf("            IMAXBEL, OPOST, ONLCR, OCRNL, ONOCR, ONLRET,\n");
                   1266:        printf("            OFILL, HUPCL, CLOCAL, CRTSCTS, ISIG, ICANON,\n");
                   1267:        printf("            ECHO, ECHOE, ECHOK, ECHONL, NOFLSH, TOSTOP,\n");
1.48      bertrand 1268:        printf("            IEXTEN\n");
1.1       bertrand 1269: 
                   1270:        printf("    Address         : { \"ADDRESS\" [ 127 0 0 1 ] }\n");
                   1271:        printf("                      { \"HOST\" \"hostname\" }\n");
                   1272:        printf("    Connections     : { \"LISTEN\" amount of connections }\n");
                   1273:        printf("    Name            : { \"NAME\" \"filename\" }\n");
                   1274:        printf("    Options         : { \"OPTION\" \"option\" argument }\n");
                   1275:        printf("                      \"BIND TO DEVICE\" \"device\"\n");
                   1276:        printf("                      \"BROADCAST\"\n");
                   1277:        printf("                      \"DO NOT ROUTE\"\n");
                   1278:        printf("                      \"KEEP ALIVE\"\n");
                   1279:        printf("                      \"PRIORITY\" integer\n");
                   1280:        printf("                      \"RECEIVE BUFFER\" integer\n");
                   1281:        printf("                      \"FORCE RECEIVE BUFFER\" integer\n");
                   1282:        printf("                      \"SEND BUFFER\" integer\n");
                   1283:        printf("                      \"FORCE SEND BUFFER\" integer\n");
                   1284:        printf("                      \"RECEIVING TIMEOUT\" integer\n");
                   1285:        printf("                      \"SENDING TIMEOUT\" integer\n");
                   1286:        printf("                      \"REUSE ADDRESS\"\n");
                   1287:        printf("    Port            : { \"PORT\" port number }\n");
                   1288:        printf("    Protocol        : { \"PROTOCOL\" \"protocol\" }\n\n");
                   1289: 
1.53      bertrand 1290:        printf("    { { \"NAME\" \"filename\" } \"SEQUENTIAL\" } OPEN\n");
1.1       bertrand 1291:        printf("    { \"SCRATCH\" } OPEN\n");
                   1292:        printf("    { { \"NAME\" \"filename\" } \"UNKNOWN\" \"FORMATTED\" "
                   1293:                "\"DIRECT\" } OPEN\n");
                   1294:        printf("    { { \"NAME\" \"filename\" } \"OLD\" \"FORMATTED\" "
                   1295:                "\"KEYED\" { \"KEY\" 2 } } OPEN\n");
                   1296:        printf("    { \"STREAM\" \"READWRITE\" } OPEN\n");
                   1297:        printf("    { \"FOREIGN\" \"DATAGRAM\" } OPEN\n");
                   1298:        printf("    { \"LOCAL\" { \"NAME\" \"socket.sock\" } } OPEN\n");
1.72      bertrand 1299:        printf("    { { \"NAME\" \"/dev/ttyS1\" } { \"STTY\" \"9600,8,N,1\" "
                   1300:                "\n            { \"NO ICANON\" \"IGNBRK\" } } } OPEN\n");
1.1       bertrand 1301: 
                   1302:        return;
                   1303:    }
                   1304:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1305:    {
                   1306:        (*s_etat_processus).nombre_arguments = -1;
                   1307:        return;
                   1308:    }
                   1309: 
                   1310:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1311:    {
                   1312:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1313:        {
                   1314:            return;
                   1315:        }
                   1316:    }
                   1317: 
                   1318:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1319:            &s_objet_argument) == d_erreur)
                   1320:    {
                   1321:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1322:        return;
                   1323:    }
                   1324: 
                   1325:    if ((*s_objet_argument).type == LST)
                   1326:    {
                   1327:        l_element_courant = (struct_liste_chainee *) (*s_objet_argument).objet;
                   1328: 
                   1329:        if (l_element_courant == NULL)
                   1330:        {
                   1331:            liberation(s_etat_processus, s_objet_argument);
                   1332: 
                   1333:            (*s_etat_processus).erreur_execution =
                   1334:                    d_ex_erreur_parametre_fichier;
                   1335:            return;
                   1336:        }
                   1337: 
                   1338:        format = ' ';
                   1339:        type_domaine = ' ';
                   1340:        type_ouverture = ' ';
                   1341:        protection = ' ';
                   1342:        type_acces = ' ';
                   1343:        type_socket = ' ';
                   1344:        nom = NULL;
                   1345:        position_clef = 0;
                   1346:        port = 0;
                   1347:        type_arguments = ' ';
                   1348:        nombre_maximal_connexions = 0;
                   1349:        hote = NULL;
                   1350:        type_adresse = ' ';
                   1351:        protocole[0] = d_code_fin_chaine;
                   1352:        protocole_socket = NULL;
                   1353:        presence_port = d_faux;
                   1354:        peripherique = NULL;
                   1355:        priorite = 0;
                   1356:        buffer_emission = 0;
                   1357:        buffer_reception = 0;
                   1358:        timeout_emission = 0;
                   1359:        timeout_reception = 0;
1.45      bertrand 1360:        s_parametres_tty = NULL;
1.1       bertrand 1361: 
                   1362:        for(i = 0; i < 12; options[i++] = 'N');
                   1363: 
                   1364:        while(l_element_courant != NULL)
                   1365:        {
                   1366:            if ((*(*l_element_courant).donnee).type == CHN)
                   1367:            {
1.80      bertrand 1368:                if ((argument_majuscule = conversion_majuscule(s_etat_processus,
                   1369:                        (unsigned char *) (*(*l_element_courant).donnee).objet))
                   1370:                        == NULL)
1.1       bertrand 1371:                {
                   1372:                    (*s_etat_processus).erreur_systeme =
                   1373:                            d_es_allocation_memoire;
                   1374:                    return;
                   1375:                }
                   1376: 
                   1377:                if (strcmp(argument_majuscule, "NEW") == 0)
                   1378:                {
                   1379:                    if (type_ouverture != ' ')
                   1380:                    {
                   1381:                        liberation(s_etat_processus, s_objet_argument);
                   1382:                        free(argument_majuscule);
                   1383: 
                   1384:                        (*s_etat_processus).erreur_execution =
                   1385:                                d_ex_erreur_parametre_fichier;
                   1386:                        return;
                   1387:                    }
                   1388: 
                   1389:                    if (type_arguments == ' ')
                   1390:                    {
                   1391:                        type_arguments = 'F';
                   1392:                    }
                   1393:                    else if (type_arguments == 'S')
                   1394:                    {
                   1395:                        liberation(s_etat_processus, s_objet_argument);
                   1396:                        free(argument_majuscule);
                   1397: 
                   1398:                        (*s_etat_processus).erreur_execution =
                   1399:                                d_ex_erreur_parametre_fichier;
                   1400:                        return;
                   1401:                    }
                   1402: 
                   1403:                    type_ouverture = 'N';
                   1404:                }
                   1405:                else if (strcmp(argument_majuscule, "REPLACE") == 0)
                   1406:                {
                   1407:                    if (type_ouverture != ' ')
                   1408:                    {
                   1409:                        liberation(s_etat_processus, s_objet_argument);
                   1410:                        free(argument_majuscule);
                   1411: 
                   1412:                        (*s_etat_processus).erreur_execution =
                   1413:                                d_ex_erreur_parametre_fichier;
                   1414:                        return;
                   1415:                    }
                   1416: 
                   1417:                    if (type_arguments == ' ')
                   1418:                    {
                   1419:                        type_arguments = 'F';
                   1420:                    }
                   1421:                    else if (type_arguments == 'S')
                   1422:                    {
                   1423:                        liberation(s_etat_processus, s_objet_argument);
                   1424:                        free(argument_majuscule);
                   1425: 
                   1426:                        (*s_etat_processus).erreur_execution =
                   1427:                                d_ex_erreur_parametre_fichier;
                   1428:                        return;
                   1429:                    }
                   1430: 
                   1431:                    type_ouverture = 'R';
                   1432:                }
1.27      bertrand 1433:                else if (strcmp(argument_majuscule, "OLD") == 0)
                   1434:                {
                   1435:                    if (type_ouverture != ' ')
                   1436:                    {
                   1437:                        liberation(s_etat_processus, s_objet_argument);
                   1438:                        free(argument_majuscule);
                   1439: 
                   1440:                        (*s_etat_processus).erreur_execution =
                   1441:                                d_ex_erreur_parametre_fichier;
                   1442:                        return;
                   1443:                    }
                   1444: 
                   1445:                    if (type_arguments == ' ')
                   1446:                    {
                   1447:                        type_arguments = 'F';
                   1448:                    }
                   1449:                    else if (type_arguments == 'S')
                   1450:                    {
                   1451:                        liberation(s_etat_processus, s_objet_argument);
                   1452:                        free(argument_majuscule);
                   1453: 
                   1454:                        (*s_etat_processus).erreur_execution =
                   1455:                                d_ex_erreur_parametre_fichier;
                   1456:                        return;
                   1457:                    }
                   1458: 
                   1459:                    type_ouverture = 'O';
                   1460:                }
1.1       bertrand 1461:                else if (strcmp(argument_majuscule, "UNKNOWN") == 0)
                   1462:                {
                   1463:                    if (type_ouverture != ' ')
                   1464:                    {
                   1465:                        liberation(s_etat_processus, s_objet_argument);
                   1466:                        free(argument_majuscule);
                   1467: 
                   1468:                        (*s_etat_processus).erreur_execution =
                   1469:                                d_ex_erreur_parametre_fichier;
                   1470:                        return;
                   1471:                    }
                   1472: 
                   1473:                    if (type_arguments == ' ')
                   1474:                    {
                   1475:                        type_arguments = 'F';
                   1476:                    }
                   1477:                    else if (type_arguments == 'S')
                   1478:                    {
                   1479:                        liberation(s_etat_processus, s_objet_argument);
                   1480:                        free(argument_majuscule);
                   1481: 
                   1482:                        (*s_etat_processus).erreur_execution =
                   1483:                                d_ex_erreur_parametre_fichier;
                   1484:                        return;
                   1485:                    }
                   1486: 
                   1487:                    type_ouverture = 'U';
                   1488:                }
                   1489:                else if (strcmp(argument_majuscule, "SCRATCH") == 0)
                   1490:                {
                   1491:                    if (type_ouverture != ' ')
                   1492:                    {
                   1493:                        liberation(s_etat_processus, s_objet_argument);
                   1494:                        free(argument_majuscule);
                   1495: 
                   1496:                        (*s_etat_processus).erreur_execution =
                   1497:                                d_ex_erreur_parametre_fichier;
                   1498:                        return;
                   1499:                    }
                   1500: 
                   1501:                    if (type_arguments == ' ')
                   1502:                    {
                   1503:                        type_arguments = 'F';
                   1504:                    }
                   1505:                    else if (type_arguments == 'S')
                   1506:                    {
                   1507:                        liberation(s_etat_processus, s_objet_argument);
                   1508:                        free(argument_majuscule);
                   1509: 
                   1510:                        (*s_etat_processus).erreur_execution =
                   1511:                                d_ex_erreur_parametre_fichier;
                   1512:                        return;
                   1513:                    }
                   1514: 
                   1515:                    type_ouverture = 'S';
                   1516:                }
                   1517:                else if (strcmp(argument_majuscule, "SEQUENTIAL") == 0)
                   1518:                {
                   1519:                    if (type_acces != ' ')
                   1520:                    {
                   1521:                        liberation(s_etat_processus, s_objet_argument);
                   1522:                        free(argument_majuscule);
                   1523: 
                   1524:                        (*s_etat_processus).erreur_execution =
                   1525:                                d_ex_erreur_parametre_fichier;
                   1526:                        return;
                   1527:                    }
                   1528: 
                   1529:                    if (type_arguments == ' ')
                   1530:                    {
                   1531:                        type_arguments = 'F';
                   1532:                    }
                   1533:                    else if (type_arguments == 'S')
                   1534:                    {
                   1535:                        liberation(s_etat_processus, s_objet_argument);
                   1536:                        free(argument_majuscule);
                   1537: 
                   1538:                        (*s_etat_processus).erreur_execution =
                   1539:                                d_ex_erreur_parametre_fichier;
                   1540:                        return;
                   1541:                    }
                   1542: 
                   1543:                    type_acces = 'S';
                   1544:                }
                   1545:                else if (strcmp(argument_majuscule, "DIRECT") == 0)
                   1546:                {
                   1547:                    if (type_acces != ' ')
                   1548:                    {
                   1549:                        liberation(s_etat_processus, s_objet_argument);
                   1550:                        free(argument_majuscule);
                   1551: 
                   1552:                        (*s_etat_processus).erreur_execution =
                   1553:                                d_ex_erreur_parametre_fichier;
                   1554:                        return;
                   1555:                    }
                   1556: 
                   1557:                    if (type_arguments == ' ')
                   1558:                    {
                   1559:                        type_arguments = 'F';
                   1560:                    }
                   1561:                    else if (type_arguments == 'S')
                   1562:                    {
                   1563:                        liberation(s_etat_processus, s_objet_argument);
                   1564:                        free(argument_majuscule);
                   1565: 
                   1566:                        (*s_etat_processus).erreur_execution =
                   1567:                                d_ex_erreur_parametre_fichier;
                   1568:                        return;
                   1569:                    }
                   1570: 
                   1571:                    type_acces = 'D';
                   1572:                }
                   1573:                else if (strcmp(argument_majuscule, "KEYED") == 0)
                   1574:                {
                   1575:                    if (type_acces != ' ')
                   1576:                    {
                   1577:                        liberation(s_etat_processus, s_objet_argument);
                   1578:                        free(argument_majuscule);
                   1579: 
                   1580:                        (*s_etat_processus).erreur_execution =
                   1581:                                d_ex_erreur_parametre_fichier;
                   1582:                        return;
                   1583:                    }
                   1584: 
                   1585:                    if (type_arguments == ' ')
                   1586:                    {
                   1587:                        type_arguments = 'F';
                   1588:                    }
                   1589:                    else if (type_arguments == 'S')
                   1590:                    {
                   1591:                        liberation(s_etat_processus, s_objet_argument);
                   1592:                        free(argument_majuscule);
                   1593: 
                   1594:                        (*s_etat_processus).erreur_execution =
                   1595:                                d_ex_erreur_parametre_fichier;
                   1596:                        return;
                   1597:                    }
                   1598: 
                   1599:                    type_acces = 'I';
                   1600:                }
                   1601:                else if (strcmp(argument_majuscule, "READONLY") == 0)
                   1602:                {
                   1603:                    if (protection != ' ')
                   1604:                    {
                   1605:                        liberation(s_etat_processus, s_objet_argument);
                   1606:                        free(argument_majuscule);
                   1607: 
                   1608:                        (*s_etat_processus).erreur_execution =
                   1609:                                d_ex_erreur_parametre_fichier;
                   1610:                        return;
                   1611:                    }
                   1612: 
                   1613:                    protection = 'R';
                   1614:                }
                   1615:                else if (strcmp(argument_majuscule, "WRITEONLY") == 0)
                   1616:                {
                   1617:                    if (protection != ' ')
                   1618:                    {
                   1619:                        liberation(s_etat_processus, s_objet_argument);
                   1620:                        free(argument_majuscule);
                   1621: 
                   1622:                        (*s_etat_processus).erreur_execution =
                   1623:                                d_ex_erreur_parametre_fichier;
                   1624:                        return;
                   1625:                    }
                   1626: 
                   1627:                    protection = 'W';
                   1628:                }
                   1629:                else if (strcmp(argument_majuscule, "READWRITE") == 0)
                   1630:                {
                   1631:                    if (protection != ' ')
                   1632:                    {
                   1633:                        liberation(s_etat_processus, s_objet_argument);
                   1634:                        free(argument_majuscule);
                   1635: 
                   1636:                        (*s_etat_processus).erreur_execution =
                   1637:                                d_ex_erreur_parametre_fichier;
                   1638:                        return;
                   1639:                    }
                   1640: 
                   1641:                    protection = 'N';
                   1642:                }
                   1643:                else if (strcmp(argument_majuscule, "FORMATTED") == 0)
                   1644:                {
                   1645:                    if (format != ' ')
                   1646:                    {
                   1647:                        liberation(s_etat_processus, s_objet_argument);
                   1648:                        free(argument_majuscule);
                   1649: 
                   1650:                        (*s_etat_processus).erreur_execution =
                   1651:                                d_ex_erreur_parametre_fichier;
                   1652:                        return;
                   1653:                    }
                   1654: 
                   1655:                    format = 'N';
                   1656:                }
                   1657:                else if (strcmp(argument_majuscule, "UNFORMATTED") == 0)
                   1658:                {
                   1659:                    if (format != ' ')
                   1660:                    {
                   1661:                        liberation(s_etat_processus, s_objet_argument);
                   1662:                        free(argument_majuscule);
                   1663: 
                   1664:                        (*s_etat_processus).erreur_execution =
                   1665:                                d_ex_erreur_parametre_fichier;
                   1666:                        return;
                   1667:                    }
                   1668: 
                   1669:                    format = 'Y';
                   1670:                }
                   1671:                else if (strcmp(argument_majuscule, "FLOW") == 0)
                   1672:                {
                   1673:                    if (format != ' ')
                   1674:                    {
                   1675:                        liberation(s_etat_processus, s_objet_argument);
                   1676:                        free(argument_majuscule);
                   1677: 
                   1678:                        (*s_etat_processus).erreur_execution =
                   1679:                                d_ex_erreur_parametre_fichier;
                   1680:                        return;
                   1681:                    }
                   1682: 
                   1683:                    format = 'F';
                   1684:                }
                   1685:                else if (strcmp(argument_majuscule, "STREAM") == 0)
                   1686:                {
                   1687:                    if (type_socket != ' ')
                   1688:                    {
                   1689:                        liberation(s_etat_processus, s_objet_argument);
                   1690:                        free(argument_majuscule);
                   1691: 
                   1692:                        (*s_etat_processus).erreur_execution =
                   1693:                                d_ex_erreur_parametre_fichier;
                   1694:                        return;
                   1695:                    }
                   1696: 
                   1697:                    if (type_arguments == ' ')
                   1698:                    {
                   1699:                        type_arguments = 'S';
                   1700:                    }
                   1701:                    else if (type_arguments == 'F')
                   1702:                    {
                   1703:                        liberation(s_etat_processus, s_objet_argument);
                   1704:                        free(argument_majuscule);
                   1705: 
                   1706:                        (*s_etat_processus).erreur_execution =
                   1707:                                d_ex_erreur_parametre_fichier;
                   1708:                        return;
                   1709:                    }
                   1710: 
                   1711:                    type_socket = 'S';
                   1712:                }
                   1713:                else if (strcmp(argument_majuscule, "DATAGRAM") == 0)
                   1714:                {
                   1715:                    if (type_socket != ' ')
                   1716:                    {
                   1717:                        liberation(s_etat_processus, s_objet_argument);
                   1718:                        free(argument_majuscule);
                   1719: 
                   1720:                        (*s_etat_processus).erreur_execution =
                   1721:                                d_ex_erreur_parametre_fichier;
                   1722:                        return;
                   1723:                    }
                   1724: 
                   1725:                    type_socket = 'D';
                   1726:                }
                   1727:                else if (strcmp(argument_majuscule, "SEQUENTIAL DATAGRAM") == 0)
                   1728:                {
                   1729:                    if (type_socket != ' ')
                   1730:                    {
                   1731:                        liberation(s_etat_processus, s_objet_argument);
                   1732:                        free(argument_majuscule);
                   1733: 
                   1734:                        (*s_etat_processus).erreur_execution =
                   1735:                                d_ex_erreur_parametre_fichier;
                   1736:                        return;
                   1737:                    }
                   1738: 
                   1739:                    if (type_arguments == ' ')
                   1740:                    {
                   1741:                        type_arguments = 'S';
                   1742:                    }
                   1743:                    else if (type_arguments == 'F')
                   1744:                    {
                   1745:                        liberation(s_etat_processus, s_objet_argument);
                   1746:                        free(argument_majuscule);
                   1747: 
                   1748:                        (*s_etat_processus).erreur_execution =
                   1749:                                d_ex_erreur_parametre_fichier;
                   1750:                        return;
                   1751:                    }
                   1752: 
                   1753:                    type_socket = 'Q';
                   1754:                }
                   1755:                else if (strcmp(argument_majuscule, "RAW") == 0)
                   1756:                {
                   1757:                    if (type_socket != ' ')
                   1758:                    {
                   1759:                        liberation(s_etat_processus, s_objet_argument);
                   1760:                        free(argument_majuscule);
                   1761: 
                   1762:                        (*s_etat_processus).erreur_execution =
                   1763:                                d_ex_erreur_parametre_fichier;
                   1764:                        return;
                   1765:                    }
                   1766: 
                   1767:                    if (type_arguments == ' ')
                   1768:                    {
                   1769:                        type_arguments = 'S';
                   1770:                    }
                   1771:                    else if (type_arguments == 'F')
                   1772:                    {
                   1773:                        liberation(s_etat_processus, s_objet_argument);
                   1774:                        free(argument_majuscule);
                   1775: 
                   1776:                        (*s_etat_processus).erreur_execution =
                   1777:                                d_ex_erreur_parametre_fichier;
                   1778:                        return;
                   1779:                    }
                   1780: 
                   1781:                    type_socket = 'R';
                   1782:                }
                   1783:                else if (strcmp(argument_majuscule, "ROBUST DATAGRAM") == 0)
                   1784:                {
                   1785:                    if (type_socket != ' ')
                   1786:                    {
                   1787:                        liberation(s_etat_processus, s_objet_argument);
                   1788:                        free(argument_majuscule);
                   1789: 
                   1790:                        (*s_etat_processus).erreur_execution =
                   1791:                                d_ex_erreur_parametre_fichier;
                   1792:                        return;
                   1793:                    }
                   1794: 
                   1795:                    if (type_arguments == ' ')
                   1796:                    {
                   1797:                        type_arguments = 'S';
                   1798:                    }
                   1799:                    else if (type_arguments == 'F')
                   1800:                    {
                   1801:                        liberation(s_etat_processus, s_objet_argument);
                   1802:                        free(argument_majuscule);
                   1803: 
                   1804:                        (*s_etat_processus).erreur_execution =
                   1805:                                d_ex_erreur_parametre_fichier;
                   1806:                        return;
                   1807:                    }
                   1808: 
                   1809:                    type_socket = 'M';
                   1810:                }
                   1811:                else if (strcmp(argument_majuscule, "LOCAL") == 0)
                   1812:                {
                   1813:                    if (type_domaine != ' ')
                   1814:                    {
                   1815:                        liberation(s_etat_processus, s_objet_argument);
                   1816:                        free(argument_majuscule);
                   1817: 
                   1818:                        (*s_etat_processus).erreur_execution =
                   1819:                                d_ex_erreur_parametre_fichier;
                   1820:                        return;
                   1821:                    }
                   1822: 
                   1823:                    if (type_arguments == ' ')
                   1824:                    {
                   1825:                        type_arguments = 'S';
                   1826:                    }
                   1827:                    else if (type_arguments == 'F')
                   1828:                    {
                   1829:                        liberation(s_etat_processus, s_objet_argument);
                   1830:                        free(argument_majuscule);
                   1831: 
                   1832:                        (*s_etat_processus).erreur_execution =
                   1833:                                d_ex_erreur_parametre_fichier;
                   1834:                        return;
                   1835:                    }
                   1836: 
                   1837:                    type_domaine = 'L';
                   1838:                }
                   1839:                else if (strcmp(argument_majuscule, "FOREIGN") == 0)
                   1840:                {
                   1841:                    if (type_domaine != ' ')
                   1842:                    {
                   1843:                        liberation(s_etat_processus, s_objet_argument);
                   1844:                        free(argument_majuscule);
                   1845: 
                   1846:                        (*s_etat_processus).erreur_execution =
                   1847:                                d_ex_erreur_parametre_fichier;
                   1848:                        return;
                   1849:                    }
                   1850: 
                   1851:                    if (type_arguments == ' ')
                   1852:                    {
                   1853:                        type_arguments = 'S';
                   1854:                    }
                   1855:                    else if (type_arguments == 'F')
                   1856:                    {
                   1857:                        liberation(s_etat_processus, s_objet_argument);
                   1858:                        free(argument_majuscule);
                   1859: 
                   1860:                        (*s_etat_processus).erreur_execution =
                   1861:                                d_ex_erreur_parametre_fichier;
                   1862:                        return;
                   1863:                    }
                   1864: 
                   1865:                    type_domaine = 'F';
                   1866:                }
                   1867:                else if (strcmp(argument_majuscule, "IPV4") == 0)
                   1868:                {
                   1869:                    if (strcmp(protocole, "") != 0)
                   1870:                    {
                   1871:                        liberation(s_etat_processus, s_objet_argument);
                   1872:                        free(argument_majuscule);
                   1873: 
                   1874:                        (*s_etat_processus).erreur_execution =
                   1875:                                d_ex_erreur_parametre_fichier;
                   1876:                        return;
                   1877:                    }
                   1878: 
                   1879:                    if (type_arguments == ' ')
                   1880:                    {
                   1881:                        type_arguments = 'S';
                   1882:                    }
                   1883:                    else if (type_arguments == 'F')
                   1884:                    {
                   1885:                        liberation(s_etat_processus, s_objet_argument);
                   1886:                        free(argument_majuscule);
                   1887: 
                   1888:                        (*s_etat_processus).erreur_execution =
                   1889:                                d_ex_erreur_parametre_fichier;
                   1890:                        return;
                   1891:                    }
                   1892: 
                   1893:                    strcpy(protocole, "IPV4");
                   1894:                }
                   1895:                else if (strcmp(argument_majuscule, "IPV6") == 0)
                   1896:                {
                   1897:                    if (strcmp(protocole, "") != 0)
                   1898:                    {
                   1899:                        liberation(s_etat_processus, s_objet_argument);
                   1900:                        free(argument_majuscule);
                   1901: 
                   1902:                        (*s_etat_processus).erreur_execution =
                   1903:                                d_ex_erreur_parametre_fichier;
                   1904:                        return;
                   1905:                    }
                   1906: 
                   1907:                    if (type_arguments == ' ')
                   1908:                    {
                   1909:                        type_arguments = 'S';
                   1910:                    }
                   1911:                    else if (type_arguments == 'F')
                   1912:                    {
                   1913:                        liberation(s_etat_processus, s_objet_argument);
                   1914:                        free(argument_majuscule);
                   1915: 
                   1916:                        (*s_etat_processus).erreur_execution =
                   1917:                                d_ex_erreur_parametre_fichier;
                   1918:                        return;
                   1919:                    }
                   1920: 
                   1921:                    strcpy(protocole, "IPV6");
                   1922:                }
                   1923:                else if (strcmp(argument_majuscule, "UNIX") == 0)
                   1924:                {
                   1925:                    if (strcmp(protocole, "") != 0)
                   1926:                    {
                   1927:                        liberation(s_etat_processus, s_objet_argument);
                   1928:                        free(argument_majuscule);
                   1929: 
                   1930:                        (*s_etat_processus).erreur_execution =
                   1931:                                d_ex_erreur_parametre_fichier;
                   1932:                        return;
                   1933:                    }
                   1934: 
                   1935:                    if (type_arguments == ' ')
                   1936:                    {
                   1937:                        type_arguments = 'S';
                   1938:                    }
                   1939:                    else if (type_arguments == 'F')
                   1940:                    {
                   1941:                        liberation(s_etat_processus, s_objet_argument);
                   1942:                        free(argument_majuscule);
                   1943: 
                   1944:                        (*s_etat_processus).erreur_execution =
                   1945:                                d_ex_erreur_parametre_fichier;
                   1946:                        return;
                   1947:                    }
                   1948: 
                   1949:                    strcpy(protocole, "UNIX");
                   1950:                }
                   1951:                else
                   1952:                {
                   1953:                    liberation(s_etat_processus, s_objet_argument);
                   1954:                    free(argument_majuscule);
                   1955: 
                   1956:                    (*s_etat_processus).erreur_execution =
                   1957:                            d_ex_erreur_parametre_fichier;
                   1958:                    return;
                   1959:                }
                   1960: 
                   1961:                free(argument_majuscule);
                   1962:            }
                   1963:            else if ((*(*l_element_courant).donnee).type == LST)
                   1964:            {
                   1965:                l_element_courant_sous_objet =
                   1966:                        (*(*l_element_courant).donnee).objet;
                   1967: 
                   1968:                nombre_elements = 0;
                   1969:                while(l_element_courant_sous_objet != NULL)
                   1970:                {
                   1971:                    nombre_elements++;
                   1972:                    l_element_courant_sous_objet =
                   1973:                            (*l_element_courant_sous_objet).suivant;
                   1974:                }
                   1975: 
                   1976:                l_element_courant_sous_objet =
                   1977:                        (*(*l_element_courant).donnee).objet;
                   1978: 
                   1979:                if (nombre_elements == 2)
                   1980:                {
                   1981:                    if ((*(*l_element_courant_sous_objet).donnee).type == CHN)
                   1982:                    {
                   1983:                        if ((argument_majuscule = conversion_majuscule(
1.80      bertrand 1984:                                s_etat_processus, (unsigned char *)
1.1       bertrand 1985:                                (*(*l_element_courant_sous_objet)
                   1986:                                .donnee).objet)) == NULL)
                   1987:                        {
                   1988:                            (*s_etat_processus).erreur_systeme =
                   1989:                                    d_es_allocation_memoire;
                   1990:                            return;
                   1991:                        }
                   1992: 
                   1993:                        l_element_courant_sous_objet =
                   1994:                                (*l_element_courant_sous_objet).suivant;
                   1995: 
                   1996:                        if (strcmp(argument_majuscule, "NAME") == 0)
                   1997:                        {
                   1998:                            if ((*(*l_element_courant_sous_objet).donnee).type
                   1999:                                   == CHN)
                   2000:                            {
                   2001:                                if (nom != NULL)
                   2002:                                {
                   2003:                                    liberation(s_etat_processus,
                   2004:                                            s_objet_argument);
                   2005:                                    free(argument_majuscule);
                   2006: 
                   2007:                                    (*s_etat_processus).erreur_execution =
                   2008:                                            d_ex_erreur_parametre_fichier;
                   2009:                                    return;
                   2010:                                }
                   2011: 
                   2012:                                nom = (unsigned char *)
                   2013:                                        (*(*l_element_courant_sous_objet)
                   2014:                                        .donnee).objet;
                   2015:                            }
                   2016:                            else
                   2017:                            {
                   2018:                                liberation(s_etat_processus, s_objet_argument);
                   2019:                                free(argument_majuscule);
                   2020: 
                   2021:                                (*s_etat_processus).erreur_execution =
                   2022:                                        d_ex_erreur_parametre_fichier;
                   2023:                                return;
                   2024:                            }
                   2025:                        }
                   2026:                        else if (strcmp(argument_majuscule, "OPTION") == 0)
                   2027:                        {
                   2028:                            if ((*(*l_element_courant_sous_objet).donnee).type
                   2029:                                   == CHN)
                   2030:                            {
                   2031:                                if (type_arguments == ' ')
                   2032:                                {
                   2033:                                    type_arguments = 'S';
                   2034:                                }
                   2035:                                else if (type_arguments == 'F')
                   2036:                                {
                   2037:                                    liberation(s_etat_processus,
                   2038:                                            s_objet_argument);
                   2039:                                    free(argument_majuscule);
                   2040: 
                   2041:                                    (*s_etat_processus).erreur_execution =
                   2042:                                            d_ex_erreur_parametre_fichier;
                   2043:                                    return;
                   2044:                                }
                   2045:                            }
                   2046: 
                   2047:                            free(argument_majuscule);
                   2048: 
                   2049:                            if ((argument_majuscule = conversion_majuscule(
1.80      bertrand 2050:                                    s_etat_processus, (unsigned char *)
1.1       bertrand 2051:                                    (*(*l_element_courant_sous_objet)
                   2052:                                    .donnee).objet)) == NULL)
                   2053:                            {
                   2054:                                (*s_etat_processus).erreur_systeme =
                   2055:                                        d_es_allocation_memoire;
                   2056:                                return;
                   2057:                            }
                   2058: 
                   2059:                            if (strcmp(argument_majuscule, "BROADCAST") == 0)
                   2060:                            {
                   2061:                                if (options[d_BROADCAST] == 'Y')
                   2062:                                {
                   2063:                                    liberation(s_etat_processus,
                   2064:                                            s_objet_argument);
                   2065:                                    free(argument_majuscule);
                   2066: 
                   2067:                                    (*s_etat_processus).erreur_execution =
                   2068:                                            d_ex_erreur_parametre_fichier;
                   2069:                                    return;
                   2070:                                }
                   2071: 
                   2072:                                options[d_BROADCAST] = 'Y';
                   2073:                            }
                   2074:                            else if (strcmp(argument_majuscule, "DO NOT ROUTE")
                   2075:                                    == 0)
                   2076:                            {
                   2077:                                if (options[d_DONT_ROUTE] == 'Y')
                   2078:                                {
                   2079:                                    liberation(s_etat_processus,
                   2080:                                            s_objet_argument);
                   2081:                                    free(argument_majuscule);
                   2082: 
                   2083:                                    (*s_etat_processus).erreur_execution =
                   2084:                                            d_ex_erreur_parametre_fichier;
                   2085:                                    return;
                   2086:                                }
                   2087: 
                   2088:                                options[d_DONT_ROUTE] = 'Y';
                   2089:                            }
                   2090:                            else if (strcmp(argument_majuscule, "KEEP ALIVE")
                   2091:                                    == 0)
                   2092:                            {
                   2093:                                if (options[d_KEEP_ALIVE] == 'Y')
                   2094:                                {
                   2095:                                    liberation(s_etat_processus,
                   2096:                                            s_objet_argument);
                   2097:                                    free(argument_majuscule);
                   2098: 
                   2099:                                    (*s_etat_processus).erreur_execution =
                   2100:                                            d_ex_erreur_parametre_fichier;
                   2101:                                    return;
                   2102:                                }
                   2103: 
                   2104:                                options[d_KEEP_ALIVE] = 'Y';
                   2105:                            }
                   2106:                            else if (strcmp(argument_majuscule, "REUSE ADDRESS")
                   2107:                                    == 0)
                   2108:                            {
                   2109:                                if (options[d_REUSE_ADDRESS] == 'Y')
                   2110:                                {
                   2111:                                    liberation(s_etat_processus,
                   2112:                                            s_objet_argument);
                   2113:                                    free(argument_majuscule);
                   2114: 
                   2115:                                    (*s_etat_processus).erreur_execution =
                   2116:                                            d_ex_erreur_parametre_fichier;
                   2117:                                    return;
                   2118:                                }
                   2119: 
                   2120:                                options[d_REUSE_ADDRESS] = 'Y';
                   2121:                            }
                   2122:                            else
                   2123:                            {
                   2124:                                liberation(s_etat_processus,
                   2125:                                        s_objet_argument);
                   2126:                                free(argument_majuscule);
                   2127: 
                   2128:                                (*s_etat_processus).erreur_execution =
                   2129:                                        d_ex_erreur_parametre_fichier;
                   2130:                                return;
                   2131:                            }
                   2132:                        }
                   2133:                        else if (strcmp(argument_majuscule, "HOST") == 0)
                   2134:                        {
                   2135:                            if ((*(*l_element_courant_sous_objet).donnee).type
                   2136:                                   == CHN)
                   2137:                            {
                   2138:                                if (type_arguments == ' ')
                   2139:                                {
                   2140:                                    type_arguments = 'S';
                   2141:                                }
                   2142:                                else if (type_arguments == 'F')
                   2143:                                {
                   2144:                                    liberation(s_etat_processus,
                   2145:                                            s_objet_argument);
                   2146:                                    free(argument_majuscule);
                   2147: 
                   2148:                                    (*s_etat_processus).erreur_execution =
                   2149:                                            d_ex_erreur_parametre_fichier;
                   2150:                                    return;
                   2151:                                }
                   2152: 
                   2153:                                if (hote != NULL)
                   2154:                                {
                   2155:                                    liberation(s_etat_processus,
                   2156:                                            s_objet_argument);
                   2157:                                    free(argument_majuscule);
                   2158: 
                   2159:                                    (*s_etat_processus).erreur_execution =
                   2160:                                            d_ex_erreur_parametre_fichier;
                   2161:                                    return;
                   2162:                                }
                   2163: 
                   2164:                                hote = (unsigned char *)
                   2165:                                        (*(*l_element_courant_sous_objet)
                   2166:                                        .donnee).objet;
                   2167:                            }
                   2168:                            else
                   2169:                            {
                   2170:                                liberation(s_etat_processus,
                   2171:                                        s_objet_argument);
                   2172:                                free(argument_majuscule);
                   2173: 
                   2174:                                (*s_etat_processus).erreur_execution =
                   2175:                                        d_ex_erreur_parametre_fichier;
                   2176:                                return;
                   2177:                            }
                   2178:                        }
                   2179:                        else if (strcmp(argument_majuscule, "PROTOCOL") == 0)
                   2180:                        {
                   2181:                            if ((*(*l_element_courant_sous_objet).donnee).type
                   2182:                                   == CHN)
                   2183:                            {
                   2184:                                if (type_arguments == ' ')
                   2185:                                {
                   2186:                                    type_arguments = 'S';
                   2187:                                }
                   2188:                                else if (type_arguments == 'F')
                   2189:                                {
                   2190:                                    liberation(s_etat_processus,
                   2191:                                            s_objet_argument);
                   2192:                                    free(argument_majuscule);
                   2193: 
                   2194:                                    (*s_etat_processus).erreur_execution =
                   2195:                                            d_ex_erreur_parametre_fichier;
                   2196:                                    return;
                   2197:                                }
                   2198: 
                   2199:                                if (protocole_socket != NULL)
                   2200:                                {
                   2201:                                    liberation(s_etat_processus,
                   2202:                                            s_objet_argument);
                   2203:                                    free(argument_majuscule);
                   2204: 
                   2205:                                    (*s_etat_processus).erreur_execution =
                   2206:                                            d_ex_erreur_parametre_fichier;
                   2207:                                    return;
                   2208:                                }
                   2209: 
                   2210:                                protocole_socket = (unsigned char *)
                   2211:                                        (*(*l_element_courant_sous_objet)
                   2212:                                        .donnee).objet;
1.42      bertrand 2213: 
1.45      bertrand 2214:                                for(i = 0; i < strlen(protocole_socket); i++)
                   2215:                                {
                   2216:                                    if ((protocole_socket[i] >= 'a') &&
                   2217:                                            (protocole_socket[i] <= 'z'))
                   2218:                                    {
1.66      bertrand 2219:                                        protocole_socket[i] = (unsigned char)
                   2220:                                                (protocole_socket[i]
                   2221:                                                - ('a' - 'A'));
1.45      bertrand 2222:                                    }
                   2223:                                }
1.1       bertrand 2224:                            }
                   2225:                            else
                   2226:                            {
                   2227:                                liberation(s_etat_processus, s_objet_argument);
                   2228:                                free(argument_majuscule);
                   2229: 
                   2230:                                (*s_etat_processus).erreur_execution =
                   2231:                                        d_ex_erreur_parametre_fichier;
                   2232:                                return;
                   2233:                            }
                   2234:                        }
                   2235:                        else if (strcmp(argument_majuscule, "KEY") == 0)
                   2236:                        {
                   2237:                            if ((*(*l_element_courant_sous_objet).donnee).type
                   2238:                                    == INT)
                   2239:                            {
                   2240:                                if (type_arguments == ' ')
                   2241:                                {
                   2242:                                    type_arguments = 'F';
                   2243:                                }
                   2244:                                else if (type_arguments == 'S')
                   2245:                                {
                   2246:                                    liberation(s_etat_processus,
                   2247:                                            s_objet_argument);
                   2248:                                    free(argument_majuscule);
                   2249: 
                   2250:                                    (*s_etat_processus).erreur_execution =
                   2251:                                            d_ex_erreur_parametre_fichier;
                   2252:                                    return;
                   2253:                                }
                   2254: 
                   2255:                                if (position_clef != 0)
                   2256:                                {
                   2257:                                    liberation(s_etat_processus,
                   2258:                                            s_objet_argument);
                   2259: 
                   2260:                                    (*s_etat_processus).erreur_execution =
                   2261:                                            d_ex_erreur_parametre_fichier;
                   2262:                                    return;
                   2263:                                }
                   2264:                                else
                   2265:                                {
                   2266:                                    if ((position_clef = (*((integer8 *)
                   2267:                                            (*(*l_element_courant_sous_objet)
                   2268:                                            .donnee).objet))) <= 0)
                   2269:                                    {
                   2270:                                        liberation(s_etat_processus,
                   2271:                                                s_objet_argument);
                   2272: 
                   2273:                                        (*s_etat_processus).erreur_execution =
                   2274:                                                d_ex_erreur_parametre_fichier;
                   2275:                                        return;
                   2276:                                    }
                   2277:                                }
                   2278:                            }
                   2279:                            else
                   2280:                            {
                   2281:                                liberation(s_etat_processus, s_objet_argument);
                   2282:                                free(argument_majuscule);
                   2283: 
                   2284:                                (*s_etat_processus).erreur_execution =
                   2285:                                        d_ex_erreur_parametre_fichier;
                   2286:                                return;
                   2287:                            }
                   2288:                        }
                   2289:                        else if (strcmp(argument_majuscule, "PORT") == 0)
                   2290:                        {
                   2291:                            if ((*(*l_element_courant_sous_objet)
                   2292:                                    .donnee).type == INT)
                   2293:                            {
                   2294:                                if (type_arguments == ' ')
                   2295:                                {
                   2296:                                    type_arguments = 'S';
                   2297:                                }
                   2298:                                else if (type_arguments == 'F')
                   2299:                                {
                   2300:                                    liberation(s_etat_processus,
                   2301:                                            s_objet_argument);
                   2302:                                    free(argument_majuscule);
                   2303: 
                   2304:                                    (*s_etat_processus).erreur_execution =
                   2305:                                            d_ex_erreur_parametre_fichier;
                   2306:                                    return;
                   2307:                                }
                   2308: 
                   2309:                                if (presence_port == d_vrai)
                   2310:                                {
                   2311:                                    liberation(s_etat_processus,
                   2312:                                            s_objet_argument);
                   2313: 
                   2314:                                    (*s_etat_processus).erreur_execution =
                   2315:                                            d_ex_erreur_parametre_fichier;
                   2316:                                    return;
                   2317:                                }
                   2318:                                else
                   2319:                                {
                   2320:                                    presence_port = d_vrai;
                   2321: 
                   2322:                                    if ((port = (*((integer8 *)
                   2323:                                            (*(*l_element_courant_sous_objet)
                   2324:                                            .donnee).objet))) < 0)
                   2325:                                    {
                   2326:                                        liberation(s_etat_processus,
                   2327:                                                s_objet_argument);
                   2328: 
                   2329:                                        (*s_etat_processus).erreur_execution =
                   2330:                                                d_ex_erreur_parametre_fichier;
                   2331:                                        return;
                   2332:                                    }
                   2333: 
                   2334:                                    if (port > 65535)
                   2335:                                    {
                   2336:                                        liberation(s_etat_processus,
                   2337:                                                s_objet_argument);
                   2338: 
                   2339:                                        (*s_etat_processus).erreur_execution =
                   2340:                                                d_ex_erreur_parametre_fichier;
                   2341:                                        return;
                   2342:                                    }
                   2343:                                }
                   2344:                            }
                   2345:                            else
                   2346:                            {
                   2347:                                liberation(s_etat_processus, s_objet_argument);
                   2348:                                free(argument_majuscule);
                   2349: 
                   2350:                                (*s_etat_processus).erreur_execution =
                   2351:                                        d_ex_erreur_parametre_fichier;
                   2352:                                return;
                   2353:                            }
                   2354:                        }
                   2355:                        else if (strcmp(argument_majuscule, "LISTEN") == 0)
                   2356:                        {
                   2357:                            if ((*(*l_element_courant_sous_objet).donnee).type
                   2358:                                    == INT)
                   2359:                            {
                   2360:                                if (type_arguments == ' ')
                   2361:                                {
                   2362:                                    type_arguments = 'S';
                   2363:                                }
1.90      bertrand 2364:                                else if (type_arguments == 'F')
1.1       bertrand 2365:                                {
                   2366:                                    liberation(s_etat_processus,
                   2367:                                            s_objet_argument);
                   2368:                                    free(argument_majuscule);
                   2369: 
                   2370:                                    (*s_etat_processus).erreur_execution =
                   2371:                                            d_ex_erreur_parametre_fichier;
                   2372:                                    return;
                   2373:                                }
                   2374: 
                   2375:                                if (nombre_maximal_connexions != 0)
                   2376:                                {
                   2377:                                    liberation(s_etat_processus,
                   2378:                                            s_objet_argument);
                   2379: 
                   2380:                                    (*s_etat_processus).erreur_execution =
                   2381:                                            d_ex_erreur_parametre_fichier;
                   2382:                                    return;
                   2383:                                }
                   2384:                                else
                   2385:                                {
                   2386:                                    if ((nombre_maximal_connexions =
                   2387:                                            (*((integer8 *)
                   2388:                                            (*(*l_element_courant_sous_objet)
                   2389:                                            .donnee).objet))) <= 0)
                   2390:                                    {
                   2391:                                        liberation(s_etat_processus,
                   2392:                                                s_objet_argument);
                   2393: 
                   2394:                                        (*s_etat_processus).erreur_execution =
                   2395:                                                d_ex_erreur_parametre_fichier;
                   2396:                                        return;
                   2397:                                    }
                   2398:                                }
                   2399:                            }
                   2400:                        }
                   2401:                        else if (strcmp(argument_majuscule, "ADDRESS") == 0)
                   2402:                        {
                   2403:                            if ((*(*l_element_courant_sous_objet)
                   2404:                                    .donnee).type == VIN)
                   2405:                            {
                   2406:                                if (type_arguments == ' ')
                   2407:                                {
                   2408:                                    type_arguments = 'S';
                   2409:                                }
                   2410:                                else if (type_arguments == 'F')
                   2411:                                {
                   2412:                                    liberation(s_etat_processus,
                   2413:                                            s_objet_argument);
                   2414:                                    free(argument_majuscule);
                   2415: 
                   2416:                                    (*s_etat_processus).erreur_execution =
                   2417:                                            d_ex_erreur_parametre_fichier;
                   2418:                                    return;
                   2419:                                }
                   2420: 
                   2421:                                if (type_adresse != ' ')
                   2422:                                {
                   2423:                                    liberation(s_etat_processus,
                   2424:                                            s_objet_argument);
                   2425: 
                   2426:                                    (*s_etat_processus).erreur_execution =
                   2427:                                            d_ex_erreur_parametre_fichier;
                   2428:                                    return;
                   2429:                                }
                   2430: 
                   2431:                                if ((*((struct_vecteur *)
                   2432:                                        (*(*l_element_courant_sous_objet)
                   2433:                                        .donnee).objet)).taille == 4)
                   2434:                                { // Adresse IPv4
                   2435:                                    type_adresse = '4';
                   2436: 
                   2437:                                    for(i = 0; i < 4; i++)
                   2438:                                    {
                   2439:                                        adresse[i] = ((integer8 *)
                   2440:                                                (*((struct_vecteur *) (*
                   2441:                                                (*l_element_courant_sous_objet)
                   2442:                                                .donnee).objet)).tableau)[i];
                   2443: 
                   2444:                                        if ((adresse[i] < 0) || (adresse[i] >
                   2445:                                                255))
                   2446:                                        {
                   2447:                                            liberation(s_etat_processus,
                   2448:                                                    s_objet_argument);
                   2449: 
                   2450:                                            (*s_etat_processus).erreur_execution
                   2451:                                                = d_ex_erreur_parametre_fichier;
                   2452:                                            return;
                   2453:                                        }
                   2454:                                    }
                   2455:                                }
                   2456:                                else if ((*((struct_vecteur *)
                   2457:                                        (*(*l_element_courant_sous_objet)
                   2458:                                        .donnee).objet)).taille == 16)
                   2459:                                { // Adresse IPv6
                   2460:                                    type_adresse = '6';
                   2461: 
                   2462:                                    for(i = 0; i < 16; i++)
                   2463:                                    {
                   2464:                                        adresse[i] = ((integer8 *)
                   2465:                                                (*((struct_vecteur *) (*
                   2466:                                                (*l_element_courant_sous_objet)
                   2467:                                                .donnee).objet)).tableau)[i];
                   2468: 
                   2469:                                        if ((adresse[i] < 0) || (adresse[i] >
                   2470:                                                255))
                   2471:                                        {
                   2472:                                            liberation(s_etat_processus,
                   2473:                                                    s_objet_argument);
                   2474: 
                   2475:                                            (*s_etat_processus).erreur_execution
                   2476:                                                = d_ex_erreur_parametre_fichier;
                   2477:                                            return;
                   2478:                                        }
                   2479:                                    }
                   2480:                                }
                   2481:                                else
                   2482:                                { // Adresse non supportée
                   2483:                                    liberation(s_etat_processus,
                   2484:                                            s_objet_argument);
                   2485: 
                   2486:                                    (*s_etat_processus).erreur_execution =
                   2487:                                            d_ex_erreur_parametre_fichier;
                   2488:                                    return;
                   2489:                                }
                   2490:                            }
                   2491:                        }
1.45      bertrand 2492:                        else if (strcmp(argument_majuscule, "STTY") == 0)
                   2493:                        {
                   2494:                            if ((*(*l_element_courant_sous_objet)
1.49      bertrand 2495:                                    .donnee).type == CHN)
1.45      bertrand 2496:                            {
                   2497:                                if (type_arguments == ' ')
                   2498:                                {
                   2499:                                    type_arguments = 'F';
                   2500:                                }
                   2501:                                else if (type_arguments == 'S')
                   2502:                                {
                   2503:                                    liberation(s_etat_processus,
                   2504:                                            s_objet_argument);
                   2505:                                    free(argument_majuscule);
                   2506: 
                   2507:                                    (*s_etat_processus).erreur_execution =
                   2508:                                            d_ex_erreur_parametre_fichier;
                   2509:                                    return;
                   2510:                                }
                   2511: 
1.49      bertrand 2512:                                s_parametres_tty = (*l_element_courant).donnee;
1.45      bertrand 2513:                            }
                   2514:                        }
1.1       bertrand 2515:                        else
                   2516:                        {
                   2517:                            liberation(s_etat_processus, s_objet_argument);
                   2518:                            free(argument_majuscule);
                   2519: 
                   2520:                            (*s_etat_processus).erreur_execution =
                   2521:                                    d_ex_erreur_parametre_fichier;
                   2522:                            return;
                   2523:                        }
                   2524: 
                   2525:                        free(argument_majuscule);
                   2526:                    }
                   2527:                    else
                   2528:                    {
                   2529:                        liberation(s_etat_processus, s_objet_argument);
                   2530:                        (*s_etat_processus).erreur_execution =
                   2531:                                d_ex_erreur_parametre_fichier;
                   2532: 
                   2533:                        return;
                   2534:                    }
                   2535:                }
                   2536:                else if (nombre_elements == 3)
                   2537:                {
                   2538:                    if ((*(*l_element_courant_sous_objet).donnee).type == CHN)
                   2539:                    {
                   2540:                        if ((argument_majuscule = conversion_majuscule(
1.80      bertrand 2541:                                s_etat_processus, (unsigned char *)
1.1       bertrand 2542:                                (*(*l_element_courant_sous_objet)
                   2543:                                .donnee).objet)) == NULL)
                   2544:                        {
                   2545:                            (*s_etat_processus).erreur_systeme =
                   2546:                                    d_es_allocation_memoire;
                   2547:                            return;
                   2548:                        }
                   2549: 
                   2550:                        if (strcmp(argument_majuscule, "OPTION") == 0)
                   2551:                        {
                   2552:                            if (type_arguments == ' ')
                   2553:                            {
                   2554:                                type_arguments = 'S';
                   2555:                            }
                   2556:                            else if (type_arguments == 'F')
                   2557:                            {
                   2558:                                liberation(s_etat_processus, s_objet_argument);
                   2559:                                free(argument_majuscule);
                   2560: 
                   2561:                                (*s_etat_processus).erreur_execution =
                   2562:                                        d_ex_erreur_parametre_fichier;
                   2563:                                return;
                   2564:                            }
                   2565: 
                   2566:                            free(argument_majuscule);
                   2567: 
                   2568:                            l_element_courant_sous_objet =
                   2569:                                    (*l_element_courant_sous_objet).suivant;
                   2570: 
                   2571:                            if ((*(*l_element_courant_sous_objet)
                   2572:                                    .donnee).type != CHN)
                   2573:                            {
                   2574:                                liberation(s_etat_processus, s_objet_argument);
                   2575: 
                   2576:                                (*s_etat_processus).erreur_execution =
                   2577:                                        d_ex_erreur_parametre_fichier;
                   2578:                                return;
                   2579:                            }
                   2580: 
                   2581:                            if ((argument_majuscule = conversion_majuscule(
1.80      bertrand 2582:                                    s_etat_processus, (unsigned char *)
1.1       bertrand 2583:                                    (*(*l_element_courant_sous_objet)
                   2584:                                    .donnee).objet)) == NULL)
                   2585:                            {
                   2586:                                (*s_etat_processus).erreur_systeme =
                   2587:                                        d_es_allocation_memoire;
                   2588:                                return;
                   2589:                            }
                   2590: 
                   2591:                            l_element_courant_sous_objet =
                   2592:                                    (*l_element_courant_sous_objet).suivant;
                   2593: 
                   2594:                            if (strcmp(argument_majuscule, "BIND TO DEVICE")
                   2595:                                    == 0)
                   2596:                            {
                   2597:                                if ((*(*l_element_courant_sous_objet)
                   2598:                                        .donnee).type != CHN)
                   2599:                                {
                   2600:                                    liberation(s_etat_processus,
                   2601:                                            s_objet_argument);
                   2602:                                    free(argument_majuscule);
                   2603: 
                   2604:                                    (*s_etat_processus).erreur_execution =
                   2605:                                            d_ex_erreur_parametre_fichier;
                   2606:                                    return;
                   2607:                                }
                   2608: 
                   2609:                                if (options[d_BIND_TO_DEVICE] == 'Y')
                   2610:                                {
                   2611:                                    liberation(s_etat_processus,
                   2612:                                            s_objet_argument);
                   2613:                                    free(argument_majuscule);
                   2614: 
                   2615:                                    (*s_etat_processus).erreur_execution =
                   2616:                                            d_ex_erreur_parametre_fichier;
                   2617:                                    return;
                   2618:                                }
                   2619: 
                   2620:                                options[d_BIND_TO_DEVICE] = 'Y';
                   2621: 
                   2622:                                peripherique = (unsigned char *)
                   2623:                                        (*(*l_element_courant_sous_objet)
                   2624:                                        .donnee).objet;
                   2625:                            }
                   2626:                            else if (strcmp(argument_majuscule, "PRIORITY")
                   2627:                                    == 0)
                   2628:                            {
                   2629:                                if ((*(*l_element_courant_sous_objet)
                   2630:                                        .donnee).type != INT)
                   2631:                                {
                   2632:                                    liberation(s_etat_processus,
                   2633:                                            s_objet_argument);
                   2634:                                    free(argument_majuscule);
                   2635: 
                   2636:                                    (*s_etat_processus).erreur_execution =
                   2637:                                            d_ex_erreur_parametre_fichier;
                   2638:                                    return;
                   2639:                                }
                   2640: 
                   2641:                                if (options[d_PRIORITY] == 'Y')
                   2642:                                {
                   2643:                                    liberation(s_etat_processus,
                   2644:                                            s_objet_argument);
                   2645:                                    free(argument_majuscule);
                   2646: 
                   2647:                                    (*s_etat_processus).erreur_execution =
                   2648:                                            d_ex_erreur_parametre_fichier;
                   2649:                                    return;
                   2650:                                }
                   2651: 
                   2652:                                options[d_PRIORITY] = 'Y';
                   2653: 
                   2654:                                priorite = (int) (*((integer8 *)
                   2655:                                        (*(*l_element_courant_sous_objet)
                   2656:                                        .donnee).objet));
                   2657:                            }
                   2658:                            else if (strcmp(argument_majuscule,
                   2659:                                    "RECEIVE BUFFER") == 0)
                   2660:                            {
                   2661:                                if ((*(*l_element_courant_sous_objet)
                   2662:                                        .donnee).type != INT)
                   2663:                                {
                   2664:                                    liberation(s_etat_processus,
                   2665:                                            s_objet_argument);
                   2666:                                    free(argument_majuscule);
                   2667: 
                   2668:                                    (*s_etat_processus).erreur_execution =
                   2669:                                            d_ex_erreur_parametre_fichier;
                   2670:                                    return;
                   2671:                                }
                   2672: 
                   2673:                                if ((options[d_RECEIVE_BUFFER] == 'Y') ||
                   2674:                                        (options[d_FORCE_RECEIVE_BUFFER]
                   2675:                                        == 'Y'))
                   2676:                                {
                   2677:                                    liberation(s_etat_processus,
                   2678:                                            s_objet_argument);
                   2679:                                    free(argument_majuscule);
                   2680: 
                   2681:                                    (*s_etat_processus).erreur_execution =
                   2682:                                            d_ex_erreur_parametre_fichier;
                   2683:                                    return;
                   2684:                                }
                   2685: 
                   2686:                                options[d_RECEIVE_BUFFER] = 'Y';
                   2687: 
                   2688:                                buffer_reception = (int) (*((integer8 *)
                   2689:                                        (*(*l_element_courant_sous_objet)
                   2690:                                        .donnee).objet));
                   2691:                            }
                   2692:                            else if (strcmp(argument_majuscule,
                   2693:                                    "FORCE RECEIVE BUFFER") == 0)
                   2694:                            {
                   2695:                                if ((*(*l_element_courant_sous_objet)
                   2696:                                        .donnee).type != INT)
                   2697:                                {
                   2698:                                    liberation(s_etat_processus,
                   2699:                                            s_objet_argument);
                   2700:                                    free(argument_majuscule);
                   2701: 
                   2702:                                    (*s_etat_processus).erreur_execution =
                   2703:                                            d_ex_erreur_parametre_fichier;
                   2704:                                    return;
                   2705:                                }
                   2706: 
                   2707:                                if ((options[d_RECEIVE_BUFFER] == 'Y') ||
                   2708:                                        (options[d_FORCE_RECEIVE_BUFFER]
                   2709:                                        == 'Y'))
                   2710:                                {
                   2711:                                    liberation(s_etat_processus,
                   2712:                                            s_objet_argument);
                   2713:                                    free(argument_majuscule);
                   2714: 
                   2715:                                    (*s_etat_processus).erreur_execution =
                   2716:                                            d_ex_erreur_parametre_fichier;
                   2717:                                    return;
                   2718:                                }
                   2719: 
                   2720:                                options[d_FORCE_RECEIVE_BUFFER] = 'Y';
                   2721: 
                   2722:                                buffer_reception = (int) (*((integer8 *)
                   2723:                                        (*(*l_element_courant_sous_objet)
                   2724:                                        .donnee).objet));
                   2725:                            }
                   2726:                            else if (strcmp(argument_majuscule,
                   2727:                                    "SEND BUFFER") == 0)
                   2728:                            {
                   2729:                                if ((*(*l_element_courant_sous_objet)
                   2730:                                        .donnee).type != INT)
                   2731:                                {
                   2732:                                    liberation(s_etat_processus,
                   2733:                                            s_objet_argument);
                   2734:                                    free(argument_majuscule);
                   2735: 
                   2736:                                    (*s_etat_processus).erreur_execution =
                   2737:                                            d_ex_erreur_parametre_fichier;
                   2738:                                    return;
                   2739:                                }
                   2740: 
                   2741:                                if ((options[d_SEND_BUFFER] == 'Y') ||
                   2742:                                        (options[d_FORCE_SEND_BUFFER] == 'Y'))
                   2743:                                {
                   2744:                                    liberation(s_etat_processus,
                   2745:                                            s_objet_argument);
                   2746:                                    free(argument_majuscule);
                   2747: 
                   2748:                                    (*s_etat_processus).erreur_execution =
                   2749:                                            d_ex_erreur_parametre_fichier;
                   2750:                                    return;
                   2751:                                }
                   2752: 
                   2753:                                options[d_SEND_BUFFER] = 'Y';
                   2754: 
                   2755:                                buffer_emission = (int) (*((integer8 *)
                   2756:                                        (*(*l_element_courant_sous_objet)
                   2757:                                        .donnee).objet));
                   2758:                            }
                   2759:                            else if (strcmp(argument_majuscule,
                   2760:                                    "FORCE SEND BUFFER") == 0)
                   2761:                            {
                   2762:                                if ((*(*l_element_courant_sous_objet)
                   2763:                                        .donnee).type != INT)
                   2764:                                {
                   2765:                                    liberation(s_etat_processus,
                   2766:                                            s_objet_argument);
                   2767:                                    free(argument_majuscule);
                   2768: 
                   2769:                                    (*s_etat_processus).erreur_execution =
                   2770:                                            d_ex_erreur_parametre_fichier;
                   2771:                                    return;
                   2772:                                }
                   2773: 
                   2774:                                if ((options[d_SEND_BUFFER] == 'Y') ||
                   2775:                                        (options[d_FORCE_SEND_BUFFER] == 'Y'))
                   2776:                                {
                   2777:                                    liberation(s_etat_processus,
                   2778:                                            s_objet_argument);
                   2779:                                    free(argument_majuscule);
                   2780: 
                   2781:                                    (*s_etat_processus).erreur_execution =
                   2782:                                            d_ex_erreur_parametre_fichier;
                   2783:                                    return;
                   2784:                                }
                   2785: 
                   2786:                                options[d_FORCE_SEND_BUFFER] = 'Y';
                   2787: 
                   2788:                                buffer_emission = (int) (*((integer8 *)
                   2789:                                        (*(*l_element_courant_sous_objet)
                   2790:                                        .donnee).objet));
                   2791:                            }
                   2792:                            else if (strcmp(argument_majuscule,
                   2793:                                    "RECEIVING TIMEOUT") == 0)
                   2794:                            {
                   2795:                                if ((*(*l_element_courant_sous_objet)
                   2796:                                        .donnee).type != INT)
                   2797:                                {
                   2798:                                    liberation(s_etat_processus,
                   2799:                                            s_objet_argument);
                   2800:                                    free(argument_majuscule);
                   2801: 
                   2802:                                    (*s_etat_processus).erreur_execution =
                   2803:                                            d_ex_erreur_parametre_fichier;
                   2804:                                    return;
                   2805:                                }
                   2806: 
                   2807:                                if (options[d_RECEIVING_TIMEOUT] == 'Y')
                   2808:                                {
                   2809:                                    liberation(s_etat_processus,
                   2810:                                            s_objet_argument);
                   2811:                                    free(argument_majuscule);
                   2812: 
                   2813:                                    (*s_etat_processus).erreur_execution =
                   2814:                                            d_ex_erreur_parametre_fichier;
                   2815:                                    return;
                   2816:                                }
                   2817: 
                   2818:                                options[d_RECEIVING_TIMEOUT] = 'Y';
                   2819: 
                   2820:                                timeout_reception = (int) (*((integer8 *)
                   2821:                                        (*(*l_element_courant_sous_objet)
                   2822:                                        .donnee).objet));
                   2823:                            }
                   2824:                            else if (strcmp(argument_majuscule,
                   2825:                                    "SENDING TIMEOUT") == 0)
                   2826:                            {
                   2827:                                if ((*(*l_element_courant_sous_objet)
                   2828:                                        .donnee).type != INT)
                   2829:                                {
                   2830:                                    liberation(s_etat_processus,
                   2831:                                            s_objet_argument);
                   2832:                                    free(argument_majuscule);
                   2833: 
                   2834:                                    (*s_etat_processus).erreur_execution =
                   2835:                                            d_ex_erreur_parametre_fichier;
                   2836:                                    return;
                   2837:                                }
                   2838: 
                   2839:                                if (options[d_SENDING_TIMEOUT] == 'Y')
                   2840:                                {
                   2841:                                    liberation(s_etat_processus,
                   2842:                                            s_objet_argument);
                   2843:                                    free(argument_majuscule);
                   2844: 
                   2845:                                    (*s_etat_processus).erreur_execution =
                   2846:                                            d_ex_erreur_parametre_fichier;
                   2847:                                    return;
                   2848:                                }
                   2849: 
                   2850:                                options[d_SENDING_TIMEOUT] = 'Y';
                   2851: 
                   2852:                                timeout_emission = (int) (*((integer8 *)
                   2853:                                        (*(*l_element_courant_sous_objet)
                   2854:                                        .donnee).objet));
                   2855:                            }
                   2856:                            else
                   2857:                            {
                   2858:                                liberation(s_etat_processus, s_objet_argument);
                   2859:                                free(argument_majuscule);
                   2860: 
                   2861:                                (*s_etat_processus).erreur_execution =
                   2862:                                        d_ex_erreur_parametre_fichier;
                   2863:                                return;
                   2864:                            }
                   2865: 
                   2866:                            free(argument_majuscule);
                   2867:                        }
1.49      bertrand 2868:                        else if (strcmp(argument_majuscule, "STTY") == 0)
                   2869:                        {
                   2870:                            if (type_arguments == ' ')
                   2871:                            {
                   2872:                                type_arguments = 'F';
                   2873:                            }
                   2874:                            else if (type_arguments == 'S')
                   2875:                            {
                   2876:                                liberation(s_etat_processus, s_objet_argument);
                   2877:                                free(argument_majuscule);
                   2878: 
                   2879:                                (*s_etat_processus).erreur_execution =
                   2880:                                        d_ex_erreur_parametre_fichier;
                   2881:                                return;
                   2882:                            }
                   2883: 
                   2884:                            free(argument_majuscule);
                   2885: 
                   2886:                            l_element_courant_sous_objet =
                   2887:                                    (*l_element_courant_sous_objet).suivant;
                   2888: 
                   2889:                            if ((*(*l_element_courant_sous_objet)
                   2890:                                    .donnee).type != CHN)
                   2891:                            {
                   2892:                                liberation(s_etat_processus, s_objet_argument);
                   2893: 
                   2894:                                (*s_etat_processus).erreur_execution =
                   2895:                                        d_ex_erreur_parametre_fichier;
                   2896:                                return;
                   2897:                            }
                   2898: 
                   2899:                            l_element_courant_sous_objet =
                   2900:                                    (*l_element_courant_sous_objet).suivant;
                   2901: 
                   2902:                            if ((*(*l_element_courant_sous_objet)
                   2903:                                    .donnee).type != LST)
                   2904:                            {
                   2905:                                liberation(s_etat_processus, s_objet_argument);
                   2906: 
                   2907:                                (*s_etat_processus).erreur_execution =
                   2908:                                        d_ex_erreur_parametre_fichier;
                   2909:                                return;
                   2910:                            }
                   2911: 
                   2912:                            s_parametres_tty = (*l_element_courant).donnee;
                   2913:                        }
1.1       bertrand 2914:                        else
                   2915:                        {
                   2916:                            liberation(s_etat_processus, s_objet_argument);
                   2917:                            free(argument_majuscule);
                   2918: 
                   2919:                            (*s_etat_processus).erreur_execution =
                   2920:                                    d_ex_erreur_parametre_fichier;
                   2921:                            return;
                   2922:                        }
                   2923:                    }
                   2924:                    else
                   2925:                    {
                   2926:                        liberation(s_etat_processus, s_objet_argument);
                   2927:                        (*s_etat_processus).erreur_execution =
                   2928:                                d_ex_erreur_parametre_fichier;
                   2929: 
                   2930:                        return;
                   2931:                    }
                   2932:                }
                   2933:                else
                   2934:                {
                   2935:                    liberation(s_etat_processus, s_objet_argument);
                   2936:                    (*s_etat_processus).erreur_execution =
                   2937:                            d_ex_erreur_parametre_fichier;
                   2938: 
                   2939:                    return;
                   2940:                }
                   2941:            }
                   2942:            else
                   2943:            {
                   2944:                liberation(s_etat_processus, s_objet_argument);
                   2945: 
                   2946:                (*s_etat_processus).erreur_execution =
                   2947:                        d_ex_erreur_parametre_fichier;
                   2948:                return;
                   2949:            }
                   2950: 
                   2951:            l_element_courant = (*l_element_courant).suivant;
                   2952:        }
                   2953: 
1.56      bertrand 2954:        // Si aucun paramètre n'est discriminant, l'instruction ouvre
                   2955:        // par défaut un fichier.
                   2956: 
                   2957:        if (type_arguments == ' ')
                   2958:        {
                   2959:            type_arguments = 'F';
                   2960:        }
                   2961: 
1.1       bertrand 2962:        if (type_arguments == 'F')
                   2963:        {
                   2964:            /*
                   2965:             * Traitement des fichiers
                   2966:             */
                   2967: 
                   2968:            /*
                   2969:             * Vérification de la cohérence et comportement par défaut
                   2970:             */
                   2971: 
                   2972:            if (type_ouverture == ' ')
                   2973:            {
                   2974:                type_ouverture = 'U';
                   2975:            }
                   2976: 
                   2977:            if (type_acces == ' ')
                   2978:            {
                   2979:                type_acces = 'S';
                   2980:            }
                   2981: 
                   2982:            if (format == ' ')
                   2983:            {
                   2984:                format = 'N';
                   2985:            }
                   2986: 
                   2987:            if (protection == ' ')
                   2988:            {
                   2989:                protection = 'N';
                   2990:            }
                   2991:            
                   2992:            if ((type_ouverture == 'S') && (protection != 'N'))
                   2993:            {
                   2994:                liberation(s_etat_processus, s_objet_argument);
                   2995: 
                   2996:                (*s_etat_processus).erreur_execution =
                   2997:                        d_ex_erreur_parametre_fichier;
                   2998:                return;
                   2999:            }
                   3000: 
                   3001:            if ((type_ouverture != 'S') && (nom == NULL))
                   3002:            {
                   3003:                liberation(s_etat_processus, s_objet_argument);
                   3004: 
                   3005:                (*s_etat_processus).erreur_execution =
                   3006:                        d_ex_erreur_parametre_fichier;
                   3007:                return;
                   3008:            }
                   3009: 
                   3010:            if (((type_acces != 'I') && (position_clef != 0)) ||
1.7       bertrand 3011:                    ((type_acces == 'I') && (position_clef == 0) &&
                   3012:                    ((type_ouverture == 'N') || (type_ouverture == 'R') ||
                   3013:                    (type_ouverture == 'S'))))
1.1       bertrand 3014:            {
                   3015:                liberation(s_etat_processus, s_objet_argument);
                   3016: 
                   3017:                (*s_etat_processus).erreur_execution =
                   3018:                        d_ex_erreur_parametre_fichier;
                   3019:                return;
                   3020:            }
                   3021: 
                   3022:            if ((s_objet_resultat = allocation(s_etat_processus, FCH))
                   3023:                    == NULL)
                   3024:            {
                   3025:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3026:                return;
                   3027:            }
                   3028: 
                   3029:            if (nom == NULL)
                   3030:            {
                   3031:                if ((nom_temporaire = creation_nom_fichier(s_etat_processus,
                   3032:                        (*s_etat_processus).chemin_fichiers_temporaires))
                   3033:                        == NULL)
                   3034:                {
                   3035:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   3036:                    return;
                   3037:                }
                   3038: 
                   3039:                if ((nom = malloc((strlen(nom_temporaire)
                   3040:                        + 5) * sizeof(unsigned char))) == NULL)
                   3041:                {
                   3042:                    (*s_etat_processus).erreur_systeme =
                   3043:                            d_es_allocation_memoire;
                   3044:                    return;
                   3045:                }
                   3046: 
                   3047:                sprintf(nom, "%s.rpl", nom_temporaire);
                   3048:                free(nom_temporaire);
                   3049:            }
                   3050:            else
                   3051:            {
1.6       bertrand 3052:                if ((nom = transliteration(s_etat_processus, nom,
                   3053:                        d_locale, "UTF-8")) == NULL)
                   3054:                {
                   3055:                    liberation(s_etat_processus, s_objet_argument);
                   3056:                    liberation(s_etat_processus, s_objet_resultat);
                   3057:                    return;
                   3058:                }
1.1       bertrand 3059:            }
                   3060: 
                   3061:            /*
                   3062:             * Ouverture du fichier
                   3063:             */
                   3064: 
                   3065:            (*((struct_fichier *) (*s_objet_resultat).objet))
                   3066:                    .nom = NULL;
                   3067:            (*((struct_fichier *) (*s_objet_resultat).objet))
                   3068:                    .acces = type_acces;
                   3069:            (*((struct_fichier *) (*s_objet_resultat).objet))
                   3070:                    .binaire = format;
                   3071:            (*((struct_fichier *) (*s_objet_resultat).objet))
                   3072:                    .ouverture = type_ouverture;
                   3073:            (*((struct_fichier *) (*s_objet_resultat).objet)).pid
                   3074:                    = getpid();
                   3075:            (*((struct_fichier *) (*s_objet_resultat).objet)).tid
                   3076:                    = pthread_self();
                   3077: 
                   3078:            if (((*((struct_fichier *) (*s_objet_resultat).objet)).format =
                   3079:                    allocation(s_etat_processus, LST)) == NULL)
                   3080:            {
1.6       bertrand 3081:                free(nom);
                   3082: 
1.1       bertrand 3083:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3084:                return;
                   3085:            }
                   3086: 
                   3087:            (*(*((struct_fichier *) (*s_objet_resultat).objet))
                   3088:                    .format).objet = NULL;
                   3089: 
1.6       bertrand 3090:            descripteur = NULL;
                   3091: 
1.1       bertrand 3092:            switch(type_ouverture)
                   3093:            {
                   3094:                case 'N' :
                   3095:                {
                   3096:                    erreur = caracteristiques_fichier(s_etat_processus,
                   3097:                            nom, &existence, &ouverture, &unite);
                   3098: 
                   3099:                    if ((erreur != 0) || (unite != 0))
                   3100:                    {
1.6       bertrand 3101:                        free(nom);
                   3102: 
1.1       bertrand 3103:                        liberation(s_etat_processus, s_objet_argument);
                   3104:                        liberation(s_etat_processus, s_objet_resultat);
                   3105: 
                   3106:                        (*s_etat_processus).erreur_execution =
                   3107:                                d_ex_erreur_acces_fichier;
                   3108:                        return;
                   3109:                    }
                   3110: 
1.6       bertrand 3111:                    if (type_acces == 'S')
                   3112:                    {
                   3113:                        if ((descripteur = fopen(nom, "w+")) == NULL)
                   3114:                        {
                   3115:                            free(nom);
                   3116: 
                   3117:                            liberation(s_etat_processus, s_objet_argument);
                   3118:                            liberation(s_etat_processus, s_objet_resultat);
                   3119: 
                   3120:                            (*s_etat_processus).erreur_execution =
                   3121:                                    d_ex_erreur_acces_fichier;
                   3122:                            return;
                   3123:                        }
                   3124:                    }
                   3125:                    else
1.1       bertrand 3126:                    {
1.6       bertrand 3127:                        // Si le fichier existe, on le supprime.
                   3128: 
                   3129:                        if (unlink(nom) != 0)
                   3130:                        {
                   3131:                            free(nom);
                   3132: 
                   3133:                            liberation(s_etat_processus, s_objet_argument);
                   3134:                            liberation(s_etat_processus, s_objet_resultat);
                   3135: 
                   3136:                            (*s_etat_processus).erreur_execution =
                   3137:                                    d_ex_erreur_acces_fichier;
                   3138:                            return;
                   3139:                        }
                   3140: 
1.40      bertrand 3141:                        sqlite = NULL;
                   3142: 
1.6       bertrand 3143:                        if (sqlite3_open_v2(nom, &sqlite,
                   3144:                                SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                   3145:                                NULL) != SQLITE_OK)
                   3146:                        {
1.40      bertrand 3147:                            if (sqlite != NULL)
                   3148:                            {
                   3149:                                sqlite3_close(sqlite);
                   3150:                            }
                   3151: 
1.6       bertrand 3152:                            free(nom);
                   3153: 
                   3154:                            liberation(s_etat_processus, s_objet_argument);
                   3155:                            liberation(s_etat_processus, s_objet_resultat);
                   3156: 
                   3157:                            (*s_etat_processus).erreur_execution =
                   3158:                                    d_ex_erreur_acces_fichier;
                   3159:                            return;
                   3160:                        }
                   3161: 
                   3162:                        if ((descripteur = fopen(nom, "a+")) == NULL)
                   3163:                        {
                   3164:                            free(nom);
                   3165: 
                   3166:                            liberation(s_etat_processus, s_objet_argument);
                   3167:                            liberation(s_etat_processus, s_objet_resultat);
                   3168: 
                   3169:                            (*s_etat_processus).erreur_execution =
                   3170:                                    d_ex_erreur_acces_fichier;
                   3171:                            return;
                   3172:                        }
                   3173: 
                   3174:                        if (type_acces == 'D')
                   3175:                        {
                   3176:                            if (initialisation_fichier_acces_direct(
                   3177:                                    s_etat_processus, sqlite,
                   3178:                                    (format == 'N') ? d_faux : d_vrai)
                   3179:                                    != d_absence_erreur)
                   3180:                            {
                   3181:                                free(nom);
                   3182: 
                   3183:                                liberation(s_etat_processus, s_objet_argument);
                   3184:                                liberation(s_etat_processus, s_objet_resultat);
                   3185: 
                   3186:                                return;
                   3187:                            }
                   3188:                        }
                   3189:                        else
                   3190:                        {
1.7       bertrand 3191:                            if (position_clef == 0)
                   3192:                            {
                   3193:                                free(nom);
                   3194: 
                   3195:                                liberation(s_etat_processus, s_objet_argument);
                   3196:                                liberation(s_etat_processus, s_objet_resultat);
                   3197: 
                   3198:                                (*s_etat_processus).erreur_execution =
                   3199:                                        d_ex_erreur_parametre_fichier;
                   3200:                                return;
                   3201:                            }
                   3202: 
1.6       bertrand 3203:                            if (initialisation_fichier_acces_indexe(
1.7       bertrand 3204:                                    s_etat_processus, sqlite, position_clef,
1.6       bertrand 3205:                                    (format == 'N') ? d_faux : d_vrai)
                   3206:                                    != d_absence_erreur)
                   3207:                            {
                   3208:                                free(nom);
                   3209: 
                   3210:                                liberation(s_etat_processus, s_objet_argument);
                   3211:                                liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3212: 
1.6       bertrand 3213:                                return;
                   3214:                            }
                   3215:                        }
1.1       bertrand 3216:                    }
                   3217: 
                   3218:                    break;
                   3219:                }
                   3220: 
                   3221:                case 'O' :
                   3222:                {
1.6       bertrand 3223:                    erreur = caracteristiques_fichier(s_etat_processus, nom,
                   3224:                            &existence, &ouverture, &unite);
1.1       bertrand 3225: 
                   3226:                    if ((erreur != d_absence_erreur) || (existence == d_faux))
                   3227:                    {
1.6       bertrand 3228:                        free(nom);
                   3229: 
1.1       bertrand 3230:                        liberation(s_etat_processus, s_objet_argument);
                   3231:                        liberation(s_etat_processus, s_objet_resultat);
                   3232: 
                   3233:                        (*s_etat_processus).erreur_execution =
                   3234:                                d_ex_erreur_acces_fichier;
                   3235:                        return;
                   3236:                    }
                   3237: 
1.6       bertrand 3238:                    if (type_acces == 'S')
1.1       bertrand 3239:                    {
1.6       bertrand 3240:                        if ((descripteur = fopen(nom, "r+")) == NULL)
                   3241:                        {
                   3242:                            free(nom);
                   3243: 
                   3244:                            liberation(s_etat_processus, s_objet_argument);
                   3245:                            liberation(s_etat_processus, s_objet_resultat);
                   3246: 
                   3247:                            (*s_etat_processus).erreur_execution =
                   3248:                                    d_ex_erreur_acces_fichier;
                   3249:                            return;
                   3250:                        }
                   3251:                    }
                   3252:                    else
                   3253:                    {
1.40      bertrand 3254:                        sqlite = NULL;
                   3255: 
1.6       bertrand 3256:                        if (sqlite3_open_v2(nom, &sqlite,
                   3257:                                SQLITE_OPEN_READWRITE,
                   3258:                                NULL) != SQLITE_OK)
                   3259:                        {
1.40      bertrand 3260:                            if (sqlite != NULL)
                   3261:                            {
                   3262:                                sqlite3_close(sqlite);
                   3263:                            }
                   3264: 
1.6       bertrand 3265:                            free(nom);
                   3266: 
                   3267:                            liberation(s_etat_processus, s_objet_argument);
                   3268:                            liberation(s_etat_processus, s_objet_resultat);
                   3269: 
                   3270:                            (*s_etat_processus).erreur_execution =
                   3271:                                    d_ex_erreur_acces_fichier;
                   3272:                            return;
                   3273:                        }
                   3274: 
                   3275:                        if ((descripteur = fopen(nom, "a+")) == NULL)
                   3276:                        {
                   3277:                            free(nom);
                   3278: 
                   3279:                            liberation(s_etat_processus, s_objet_argument);
                   3280:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3281: 
1.6       bertrand 3282:                            (*s_etat_processus).erreur_execution =
                   3283:                                    d_ex_erreur_acces_fichier;
                   3284:                            return;
                   3285:                        }
1.1       bertrand 3286:                    }
                   3287: 
                   3288:                    break;
                   3289:                }
                   3290: 
                   3291:                case 'R' :
                   3292:                {
                   3293:                    erreur = caracteristiques_fichier(s_etat_processus,
                   3294:                            nom, &existence, &ouverture, &unite);
                   3295: 
                   3296:                    if ((erreur != d_absence_erreur) || (existence == d_faux))
                   3297:                    {
1.6       bertrand 3298:                        free(nom);
                   3299: 
1.1       bertrand 3300:                        liberation(s_etat_processus, s_objet_argument);
                   3301:                        liberation(s_etat_processus, s_objet_resultat);
                   3302: 
                   3303:                        (*s_etat_processus).erreur_execution =
                   3304:                                d_ex_erreur_acces_fichier;
                   3305:                        return;
                   3306:                    }
                   3307: 
                   3308:                    /* Test du verrou */
                   3309: 
                   3310:                    if ((descripteur = fopen(nom, "r")) == NULL)
                   3311:                    {
1.6       bertrand 3312:                        free(nom);
                   3313: 
1.1       bertrand 3314:                        liberation(s_etat_processus, s_objet_argument);
                   3315:                        liberation(s_etat_processus, s_objet_resultat);
                   3316: 
                   3317:                        (*s_etat_processus).erreur_execution =
                   3318:                                d_ex_erreur_acces_fichier;
                   3319:                        return;
                   3320:                    }
                   3321: 
                   3322:                    lock.l_type = F_WRLCK;
                   3323:                    lock.l_whence = SEEK_SET;
                   3324:                    lock.l_start = 0;
                   3325:                    lock.l_len = 0;
                   3326:                    lock.l_pid = getpid();
                   3327: 
                   3328:                    if (fcntl(fileno(descripteur), F_GETLK, &lock) == -1)
                   3329:                    {
1.6       bertrand 3330:                        free(nom);
                   3331: 
1.1       bertrand 3332:                        if (fclose(descripteur) != 0)
                   3333:                        {
1.6       bertrand 3334:                            liberation(s_etat_processus, s_objet_argument);
1.1       bertrand 3335:                            liberation(s_etat_processus, s_objet_resultat);
                   3336: 
                   3337:                            (*s_etat_processus).erreur_systeme =
                   3338:                                    d_es_erreur_fichier;
                   3339:                            return;
                   3340:                        }
                   3341: 
1.6       bertrand 3342:                        liberation(s_etat_processus, s_objet_argument);
1.1       bertrand 3343:                        liberation(s_etat_processus, s_objet_resultat);
                   3344: 
                   3345:                        (*s_etat_processus).erreur_systeme =
                   3346:                                d_es_erreur_fichier;
                   3347:                        return;
                   3348:                    }
                   3349: 
1.6       bertrand 3350:                    if (lock.l_type != F_UNLCK)
                   3351:                    {
                   3352:                        free(nom);
                   3353: 
                   3354:                        if (fclose(descripteur) != 0)
                   3355:                        {
                   3356:                            liberation(s_etat_processus, s_objet_argument);
                   3357:                            liberation(s_etat_processus, s_objet_resultat);
                   3358: 
                   3359:                            (*s_etat_processus).erreur_systeme =
                   3360:                                    d_es_erreur_fichier;
                   3361:                            return;
                   3362:                        }
                   3363: 
                   3364:                        liberation(s_etat_processus, s_objet_argument);
                   3365:                        liberation(s_etat_processus, s_objet_resultat);
                   3366: 
                   3367:                        (*s_etat_processus).erreur_execution =
                   3368:                                d_ex_fichier_verrouille;
                   3369:                        return;
                   3370:                    }
                   3371: 
1.1       bertrand 3372:                    if (fclose(descripteur) != 0)
                   3373:                    {
1.6       bertrand 3374:                        free(nom);
                   3375: 
                   3376:                        liberation(s_etat_processus, s_objet_argument);
1.1       bertrand 3377:                        liberation(s_etat_processus, s_objet_resultat);
                   3378: 
                   3379:                        (*s_etat_processus).erreur_systeme =
                   3380:                                d_es_erreur_fichier;
                   3381:                        return;
                   3382:                    }
                   3383: 
1.6       bertrand 3384:                    if (type_acces == 'S')
1.1       bertrand 3385:                    {
1.6       bertrand 3386:                        if ((descripteur = fopen(nom, "w+")) == NULL)
                   3387:                        {
                   3388:                            free(nom);
                   3389: 
                   3390:                            liberation(s_etat_processus, s_objet_argument);
                   3391:                            liberation(s_etat_processus, s_objet_resultat);
                   3392: 
                   3393:                            (*s_etat_processus).erreur_execution =
                   3394:                                    d_ex_erreur_acces_fichier;
                   3395:                            return;
                   3396:                        }
                   3397:                    }
                   3398:                    else
                   3399:                    {
1.40      bertrand 3400:                        sqlite = NULL;
                   3401: 
1.6       bertrand 3402:                        if (sqlite3_open_v2(nom, &sqlite,
                   3403:                                SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                   3404:                                NULL) != SQLITE_OK)
                   3405:                        {
1.40      bertrand 3406:                            if (sqlite != NULL)
                   3407:                            {
                   3408:                                sqlite3_close(sqlite);
                   3409:                            }
                   3410: 
1.6       bertrand 3411:                            free(nom);
                   3412: 
                   3413:                            liberation(s_etat_processus, s_objet_argument);
                   3414:                            liberation(s_etat_processus, s_objet_resultat);
                   3415: 
                   3416:                            (*s_etat_processus).erreur_execution =
                   3417:                                    d_ex_erreur_acces_fichier;
                   3418:                            return;
                   3419:                        }
                   3420: 
                   3421:                        // Ouverture du fichier pour pouvoir gérer les
                   3422:                        // verrous à la façon des fichiers séquentiels.
                   3423: 
                   3424:                        if ((descripteur = fopen(nom, "a+")) == NULL)
                   3425:                        {
                   3426:                            free(nom);
                   3427: 
                   3428:                            liberation(s_etat_processus, s_objet_argument);
                   3429:                            liberation(s_etat_processus, s_objet_resultat);
                   3430: 
                   3431:                            (*s_etat_processus).erreur_execution =
                   3432:                                    d_ex_erreur_acces_fichier;
                   3433:                            return;
                   3434:                        }
                   3435: 
                   3436:                        if (type_acces == 'D')
                   3437:                        {
                   3438:                            if (initialisation_fichier_acces_direct(
                   3439:                                    s_etat_processus, sqlite,
                   3440:                                    (format == 'N') ? d_faux : d_vrai)
                   3441:                                    != d_absence_erreur)
                   3442:                            {
                   3443:                                free(nom);
                   3444: 
                   3445:                                liberation(s_etat_processus, s_objet_argument);
                   3446:                                liberation(s_etat_processus, s_objet_resultat);
                   3447: 
                   3448:                                return;
                   3449:                            }
                   3450:                        }
                   3451:                        else
                   3452:                        {
1.7       bertrand 3453:                            if (position_clef == 0)
                   3454:                            {
                   3455:                                free(nom);
                   3456: 
                   3457:                                liberation(s_etat_processus, s_objet_argument);
                   3458:                                liberation(s_etat_processus, s_objet_resultat);
                   3459: 
                   3460:                                (*s_etat_processus).erreur_execution =
                   3461:                                        d_ex_erreur_parametre_fichier;
                   3462:                                return;
                   3463:                            }
                   3464: 
1.6       bertrand 3465:                            if (initialisation_fichier_acces_indexe(
1.7       bertrand 3466:                                    s_etat_processus, sqlite, position_clef,
1.6       bertrand 3467:                                    (format == 'N') ? d_faux : d_vrai)
                   3468:                                    != d_absence_erreur)
                   3469:                            {
                   3470:                                free(nom);
                   3471: 
                   3472:                                liberation(s_etat_processus, s_objet_argument);
                   3473:                                liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3474: 
1.6       bertrand 3475:                                return;
                   3476:                            }
                   3477:                        }
1.1       bertrand 3478:                    }
                   3479: 
                   3480:                    break;
                   3481:                }
                   3482: 
                   3483:                case 'U' :
                   3484:                {
                   3485:                    erreur = caracteristiques_fichier(s_etat_processus,
                   3486:                            nom, &existence, &ouverture, &unite);
                   3487: 
                   3488:                    if (erreur == d_erreur)
                   3489:                    {
1.6       bertrand 3490:                        free(nom);
                   3491: 
1.1       bertrand 3492:                        liberation(s_etat_processus, s_objet_argument);
                   3493:                        liberation(s_etat_processus, s_objet_resultat);
                   3494: 
                   3495:                        (*s_etat_processus).erreur_execution =
                   3496:                                d_ex_erreur_acces_fichier;
                   3497:                        return;
                   3498:                    }
                   3499: 
                   3500:                    if (existence == d_faux)
                   3501:                    {
1.6       bertrand 3502:                        if (type_acces == 'S')
                   3503:                        {
                   3504:                            if ((descripteur = fopen(nom, "w+")) == NULL)
                   3505:                            {
                   3506:                                free(nom);
                   3507: 
                   3508:                                liberation(s_etat_processus, s_objet_argument);
                   3509:                                liberation(s_etat_processus, s_objet_resultat);
                   3510: 
                   3511:                                (*s_etat_processus).erreur_execution =
                   3512:                                        d_ex_erreur_acces_fichier;
                   3513:                                return;
                   3514:                            }
                   3515:                        }
                   3516:                        else
1.1       bertrand 3517:                        {
1.40      bertrand 3518:                            sqlite = NULL;
                   3519: 
1.6       bertrand 3520:                            if (sqlite3_open_v2(nom, &sqlite,
                   3521:                                    SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                   3522:                                    NULL) != SQLITE_OK)
                   3523:                            {
1.40      bertrand 3524:                                if (sqlite != NULL)
                   3525:                                {
                   3526:                                    sqlite3_close(sqlite);
                   3527:                                }
                   3528: 
1.6       bertrand 3529:                                free(nom);
                   3530: 
                   3531:                                liberation(s_etat_processus, s_objet_argument);
                   3532:                                liberation(s_etat_processus, s_objet_resultat);
                   3533: 
                   3534:                                (*s_etat_processus).erreur_execution =
                   3535:                                        d_ex_erreur_acces_fichier;
                   3536:                                return;
                   3537:                            }
                   3538: 
                   3539:                            if ((descripteur = fopen(nom, "a+")) == NULL)
                   3540:                            {
                   3541:                                free(nom);
                   3542: 
                   3543:                                liberation(s_etat_processus, s_objet_argument);
                   3544:                                liberation(s_etat_processus, s_objet_resultat);
                   3545: 
                   3546:                                (*s_etat_processus).erreur_execution =
                   3547:                                        d_ex_erreur_acces_fichier;
                   3548:                                return;
                   3549:                            }
                   3550: 
                   3551:                            if (type_acces == 'D')
                   3552:                            {
                   3553:                                if (initialisation_fichier_acces_direct(
                   3554:                                        s_etat_processus, sqlite,
                   3555:                                        (format == 'N') ? d_faux : d_vrai)
                   3556:                                        != d_absence_erreur)
                   3557:                                {
                   3558:                                    free(nom);
                   3559: 
                   3560:                                    liberation(s_etat_processus,
                   3561:                                            s_objet_argument);
                   3562:                                    liberation(s_etat_processus,
                   3563:                                            s_objet_resultat);
                   3564: 
                   3565:                                    return;
                   3566:                                }
                   3567:                            }
                   3568:                            else
                   3569:                            {
1.7       bertrand 3570:                                if (position_clef == 0)
                   3571:                                {
                   3572:                                    free(nom);
                   3573: 
                   3574:                                    liberation(s_etat_processus,
                   3575:                                            s_objet_argument);
                   3576:                                    liberation(s_etat_processus,
                   3577:                                            s_objet_resultat);
                   3578: 
                   3579:                                    (*s_etat_processus).erreur_execution =
                   3580:                                            d_ex_erreur_parametre_fichier;
                   3581:                                    return;
                   3582:                                }
                   3583: 
1.6       bertrand 3584:                                if (initialisation_fichier_acces_indexe(
1.7       bertrand 3585:                                        s_etat_processus, sqlite, position_clef,
1.6       bertrand 3586:                                        (format == 'N') ? d_faux : d_vrai)
                   3587:                                        != d_absence_erreur)
                   3588:                                {
                   3589:                                    free(nom);
                   3590: 
                   3591:                                    liberation(s_etat_processus,
                   3592:                                            s_objet_argument);
                   3593:                                    liberation(s_etat_processus,
                   3594:                                            s_objet_resultat);
1.1       bertrand 3595: 
1.6       bertrand 3596:                                    return;
                   3597:                                }
                   3598:                            }
1.1       bertrand 3599:                        }
                   3600:                    }
                   3601:                    else
                   3602:                    {
1.6       bertrand 3603:                        if (type_acces == 'S')
                   3604:                        {
                   3605:                            if ((descripteur = fopen(nom, "r+")) == NULL)
                   3606:                            {
                   3607:                                free(nom);
                   3608: 
                   3609:                                liberation(s_etat_processus, s_objet_argument);
                   3610:                                liberation(s_etat_processus, s_objet_resultat);
                   3611: 
                   3612:                                (*s_etat_processus).erreur_execution =
                   3613:                                        d_ex_erreur_acces_fichier;
                   3614:                                return;
                   3615:                            }
                   3616:                        }
                   3617:                        else
1.1       bertrand 3618:                        {
1.40      bertrand 3619:                            sqlite = NULL;
                   3620: 
1.6       bertrand 3621:                            if (sqlite3_open_v2(nom, &sqlite,
                   3622:                                    SQLITE_OPEN_READWRITE,
                   3623:                                    NULL) != SQLITE_OK)
                   3624:                            {
1.40      bertrand 3625:                                if (sqlite != NULL)
                   3626:                                {
                   3627:                                    sqlite3_close(sqlite);
                   3628:                                }
                   3629: 
1.6       bertrand 3630:                                free(nom);
                   3631: 
                   3632:                                liberation(s_etat_processus, s_objet_argument);
                   3633:                                liberation(s_etat_processus, s_objet_resultat);
                   3634: 
                   3635:                                (*s_etat_processus).erreur_execution =
                   3636:                                        d_ex_erreur_acces_fichier;
                   3637:                                return;
                   3638:                            }
                   3639: 
                   3640:                            if ((descripteur = fopen(nom, "a+")) == NULL)
                   3641:                            {
                   3642:                                free(nom);
                   3643: 
                   3644:                                liberation(s_etat_processus, s_objet_argument);
                   3645:                                liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3646: 
1.6       bertrand 3647:                                (*s_etat_processus).erreur_execution =
                   3648:                                        d_ex_erreur_acces_fichier;
                   3649:                                return;
                   3650:                            }
1.1       bertrand 3651:                        }
                   3652:                    }
                   3653: 
                   3654:                    break;
                   3655:                }
                   3656: 
                   3657:                case 'S' :
                   3658:                {
                   3659:                    erreur = caracteristiques_fichier(s_etat_processus,
                   3660:                            nom, &existence, &ouverture, &unite);
                   3661: 
                   3662:                    if ((erreur != d_absence_erreur) || (existence != d_faux))
                   3663:                    {
1.6       bertrand 3664:                        free(nom);
                   3665: 
1.1       bertrand 3666:                        liberation(s_etat_processus, s_objet_argument);
                   3667:                        liberation(s_etat_processus, s_objet_resultat);
                   3668: 
                   3669:                        (*s_etat_processus).erreur_execution =
                   3670:                                d_ex_erreur_acces_fichier;
                   3671:                        return;
                   3672:                    }
                   3673: 
1.6       bertrand 3674:                    if (type_acces == 'S')
1.1       bertrand 3675:                    {
1.6       bertrand 3676:                        if ((descripteur = fopen(nom, "w+")) == NULL)
                   3677:                        {
                   3678:                            free(nom);
                   3679: 
                   3680:                            liberation(s_etat_processus, s_objet_argument);
                   3681:                            liberation(s_etat_processus, s_objet_resultat);
                   3682: 
                   3683:                            (*s_etat_processus).erreur_execution =
                   3684:                                    d_ex_erreur_acces_fichier;
                   3685:                            return;
                   3686:                        }
                   3687:                    }
                   3688:                    else
                   3689:                    {
                   3690:                        // Si le fichier existe, on le supprime.
                   3691: 
                   3692:                        if (unlink(nom) != 0)
                   3693:                        {
                   3694:                            free(nom);
                   3695: 
                   3696:                            liberation(s_etat_processus, s_objet_argument);
                   3697:                            liberation(s_etat_processus, s_objet_resultat);
                   3698: 
                   3699:                            (*s_etat_processus).erreur_execution =
                   3700:                                    d_ex_erreur_acces_fichier;
                   3701:                            return;
                   3702:                        }
                   3703: 
1.40      bertrand 3704:                        sqlite = NULL;
                   3705: 
1.6       bertrand 3706:                        if (sqlite3_open_v2(nom, &sqlite,
                   3707:                                SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                   3708:                                NULL) != SQLITE_OK)
                   3709:                        {
1.40      bertrand 3710:                            if (sqlite != NULL)
                   3711:                            {
                   3712:                                sqlite3_close(sqlite);
                   3713:                            }
                   3714: 
1.6       bertrand 3715:                            free(nom);
                   3716: 
                   3717:                            liberation(s_etat_processus, s_objet_argument);
                   3718:                            liberation(s_etat_processus, s_objet_resultat);
                   3719: 
                   3720:                            (*s_etat_processus).erreur_execution =
                   3721:                                    d_ex_erreur_acces_fichier;
                   3722:                            return;
                   3723:                        }
                   3724: 
                   3725:                        if ((descripteur = fopen(nom, "a+")) == NULL)
                   3726:                        {
                   3727:                            free(nom);
                   3728: 
                   3729:                            liberation(s_etat_processus, s_objet_argument);
                   3730:                            liberation(s_etat_processus, s_objet_resultat);
                   3731: 
                   3732:                            (*s_etat_processus).erreur_execution =
                   3733:                                    d_ex_erreur_acces_fichier;
                   3734:                            return;
                   3735:                        }
                   3736: 
                   3737:                        if (type_acces == 'D')
                   3738:                        {
                   3739:                            if (initialisation_fichier_acces_direct(
                   3740:                                    s_etat_processus, sqlite,
                   3741:                                    (format == 'N') ? d_faux : d_vrai)
                   3742:                                    != d_absence_erreur)
                   3743:                            {
                   3744:                                free(nom);
                   3745: 
                   3746:                                liberation(s_etat_processus, s_objet_argument);
                   3747:                                liberation(s_etat_processus, s_objet_resultat);
                   3748: 
                   3749:                                return;
                   3750:                            }
                   3751:                        }
                   3752:                        else
1.7       bertrand 3753:                        { 
                   3754:                            if (position_clef == 0)
                   3755:                            {
                   3756:                                free(nom);
                   3757: 
                   3758:                                liberation(s_etat_processus, s_objet_argument);
                   3759:                                liberation(s_etat_processus, s_objet_resultat);
                   3760: 
                   3761:                                (*s_etat_processus).erreur_execution =
                   3762:                                        d_ex_erreur_parametre_fichier;
                   3763:                                return;
                   3764:                            }
                   3765: 
1.6       bertrand 3766:                            if (initialisation_fichier_acces_indexe(
1.7       bertrand 3767:                                    s_etat_processus, sqlite, position_clef,
1.6       bertrand 3768:                                    (format == 'N') ? d_faux : d_vrai)
                   3769:                                    != d_absence_erreur)
                   3770:                            {
                   3771:                                free(nom);
                   3772: 
                   3773:                                liberation(s_etat_processus, s_objet_argument);
                   3774:                                liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3775: 
1.6       bertrand 3776:                                return;
                   3777:                            }
                   3778:                        }
1.1       bertrand 3779:                    }
                   3780: 
                   3781:                    break;
                   3782:                }
                   3783: 
                   3784:                default:
                   3785:                {
                   3786:                    BUG(1, printf("type_ouverture=%c\n", type_ouverture));
                   3787:                    return;
                   3788:                }
                   3789:            }
                   3790: 
                   3791:            if (((*((struct_fichier *) (*s_objet_resultat).objet)).nom =
                   3792:                    malloc((strlen(nom) + 1) *
                   3793:                    sizeof(unsigned char))) == NULL)
                   3794:            {
                   3795:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3796:                return;
                   3797:            }
                   3798: 
1.45      bertrand 3799:            if (s_parametres_tty != NULL)
                   3800:            {
                   3801:                // Affectation des paramètres du port série.
                   3802: 
                   3803:                if (tcgetattr(fileno(descripteur), &tc) != 0)
                   3804:                {
                   3805:                    liberation(s_etat_processus, s_objet_argument);
                   3806:                    liberation(s_etat_processus, s_objet_resultat);
                   3807: 
                   3808:                    (*s_etat_processus).erreur_systeme =
                   3809:                            d_ex_erreur_fichier;
                   3810:                    return;
                   3811:                }
1.46      bertrand 3812: 
1.49      bertrand 3813:                // Un test a déjà été fait pour vérifier que s_parametres_tty
                   3814:                // contient deux ou trois arguments.
                   3815: 
                   3816:                parametre_courant = ((*(struct_liste_chainee *)
                   3817:                        (*s_parametres_tty).objet)).suivant;
1.46      bertrand 3818: 
                   3819:                // Le premier paramètre concerne la vitesse du port. Il doit
                   3820:                // toujours être présent.
                   3821: 
                   3822:                if (parametre_courant == NULL)
                   3823:                {
                   3824:                    liberation(s_etat_processus, s_objet_argument);
                   3825:                    liberation(s_etat_processus, s_objet_resultat);
                   3826: 
                   3827:                    (*s_etat_processus).erreur_execution =
                   3828:                            d_ex_erreur_parametre_fichier;
                   3829:                    return;
                   3830:                }
                   3831: 
                   3832:                if ((*(*parametre_courant).donnee).type != CHN)
                   3833:                {
                   3834:                    liberation(s_etat_processus, s_objet_argument);
                   3835:                    liberation(s_etat_processus, s_objet_resultat);
                   3836: 
                   3837:                    (*s_etat_processus).erreur_execution =
                   3838:                            d_ex_erreur_parametre_fichier;
                   3839:                    return;
                   3840:                }
                   3841: 
                   3842:                if ((parametre_courant_majuscule = conversion_majuscule(
1.80      bertrand 3843:                        s_etat_processus, (*(*parametre_courant).donnee).objet))
                   3844:                        == NULL)
1.46      bertrand 3845:                {
                   3846:                    liberation(s_etat_processus, s_objet_argument);
                   3847:                    liberation(s_etat_processus, s_objet_resultat);
                   3848: 
                   3849:                    (*s_etat_processus).erreur_systeme =
                   3850:                            d_es_allocation_memoire;
                   3851:                    return;
                   3852:                }
                   3853: 
                   3854:                position = parametre_courant_majuscule;
                   3855: 
                   3856:                while((*position) != d_code_fin_chaine)
                   3857:                {
                   3858:                    if ((*position) == ',')
                   3859:                    {
                   3860:                        (*position) = ' ';
                   3861:                    }
                   3862: 
                   3863:                    position++;
                   3864:                }
                   3865: 
                   3866:                position = parametre_courant_majuscule;
                   3867: 
                   3868:                while((*position) != d_code_fin_chaine)
                   3869:                {
                   3870:                    if (isalnum((*position)) != 0)
                   3871:                    {
                   3872:                        break;
                   3873:                    }
                   3874: 
                   3875:                    position++;
                   3876:                }
                   3877: 
                   3878:                // Vitesse
                   3879: 
                   3880:                unsigned char   *vitesses[] =
1.73      bertrand 3881:                        { "50", "75", "110", "134", "150",
1.49      bertrand 3882:                        "200", "300", "600", "1200", "1800", "2400",
1.57      bertrand 3883:                        "4800", "9600", "19200", "38400",
                   3884: #ifdef B57600
                   3885:                        "57600",
                   3886: #endif
                   3887: #ifdef B115200
                   3888:                        "115200",
                   3889: #endif
                   3890: #ifdef B230400
                   3891:                        "230400",
                   3892: #endif
                   3893:                        NULL };
1.66      bertrand 3894:                tcflag_t        vitesses_constantes[] =
1.73      bertrand 3895:                        { B50, B75, B110, B134, B150, B200, B300, B600,
1.46      bertrand 3896:                        B1200, B1800, B2400, B4800, B9600, B19200, B38400,
1.57      bertrand 3897: #ifdef B57600
                   3898:                        B57600,
                   3899: #endif
                   3900: #ifdef B115200
                   3901:                        B115200,
                   3902: #endif
                   3903: #ifdef B230400
                   3904:                        B230400,
                   3905: #endif
                   3906:                        0 };
1.46      bertrand 3907:                unsigned int    vitesse_courante;
                   3908: 
                   3909:                vitesse_courante = 0;
                   3910: 
                   3911:                while(vitesses[vitesse_courante] != NULL)
                   3912:                {
                   3913:                    if (strncmp(position, vitesses[vitesse_courante],
                   3914:                            strlen(vitesses[vitesse_courante])) == 0)
                   3915:                    {
                   3916:                        if (position[strlen(vitesses[vitesse_courante])] ==
                   3917:                                d_code_espace)
                   3918:                        {
1.57      bertrand 3919: #ifdef CBAUD
1.66      bertrand 3920:                            tc.c_cflag &= ~((tcflag_t) CBAUD);
1.46      bertrand 3921:                            tc.c_cflag |= vitesses_constantes[vitesse_courante];
1.57      bertrand 3922: #else // POSIX
                   3923:                            cfsetispeed(&tc,
                   3924:                                    vitesses_constantes[vitesse_courante]);
                   3925:                            cfsetospeed(&tc,
                   3926:                                    vitesses_constantes[vitesse_courante]);
                   3927: #endif
1.46      bertrand 3928:                            position += strlen(vitesses[vitesse_courante]);
                   3929: 
                   3930:                            break;
                   3931:                        }
                   3932:                    }
                   3933: 
                   3934:                    vitesse_courante++;
                   3935:                }
                   3936: 
                   3937:                if (vitesses[vitesse_courante] == NULL)
                   3938:                {
                   3939:                    // La vitesse indiquée n'est pas une vitesse autorisée.
                   3940: 
                   3941:                    free(parametre_courant_majuscule);
                   3942:                    liberation(s_etat_processus, s_objet_argument);
                   3943:                    liberation(s_etat_processus, s_objet_resultat);
                   3944: 
                   3945:                    (*s_etat_processus).erreur_execution =
                   3946:                            d_ex_erreur_parametre_fichier;
                   3947:                    return;
                   3948:                }
                   3949: 
                   3950:                // Nombre de bits par caractère.
                   3951: 
                   3952:                while((*position) != d_code_fin_chaine)
                   3953:                {
                   3954:                    if (isalnum((*position)) != 0)
                   3955:                    {
                   3956:                        break;
                   3957:                    }
                   3958: 
                   3959:                    position++;
                   3960:                }
                   3961: 
                   3962:                switch((*position))
                   3963:                {
                   3964:                    case '5':
                   3965:                    {
1.66      bertrand 3966:                        tc.c_cflag &= ~((tcflag_t) CSIZE);
1.46      bertrand 3967:                        tc.c_cflag |= CS5;
                   3968:                        break;
                   3969:                    }
                   3970: 
                   3971:                    case '6':
                   3972:                    {
1.66      bertrand 3973:                        tc.c_cflag &= ~((tcflag_t) CSIZE);
1.46      bertrand 3974:                        tc.c_cflag |= CS6;
                   3975:                        break;
                   3976:                    }
                   3977: 
                   3978:                    case '7':
                   3979:                    {
1.66      bertrand 3980:                        tc.c_cflag &= ~((tcflag_t) CSIZE);
1.46      bertrand 3981:                        tc.c_cflag |= CS7;
                   3982:                        break;
                   3983:                    }
                   3984: 
                   3985:                    case '8':
                   3986:                    {
1.66      bertrand 3987:                        tc.c_cflag &= ~((tcflag_t) CSIZE);
1.46      bertrand 3988:                        tc.c_cflag |= CS8;
                   3989:                        break;
                   3990:                    }
                   3991: 
                   3992:                    default:
                   3993:                    {
                   3994:                        free(parametre_courant_majuscule);
                   3995:                        liberation(s_etat_processus, s_objet_argument);
                   3996:                        liberation(s_etat_processus, s_objet_resultat);
                   3997: 
                   3998:                        (*s_etat_processus).erreur_execution =
                   3999:                                d_ex_erreur_parametre_fichier;
                   4000:                        return;
                   4001:                    }
                   4002:                }
                   4003: 
                   4004:                position++;
                   4005: 
                   4006:                if ((*position) != d_code_espace)
                   4007:                {
                   4008:                    free(parametre_courant_majuscule);
                   4009:                    liberation(s_etat_processus, s_objet_argument);
                   4010:                    liberation(s_etat_processus, s_objet_resultat);
                   4011: 
                   4012:                    (*s_etat_processus).erreur_execution =
                   4013:                            d_ex_erreur_parametre_fichier;
                   4014:                    return;
                   4015:                }
                   4016: 
                   4017:                // Parité
                   4018: 
                   4019:                while((*position) != d_code_fin_chaine)
                   4020:                {
                   4021:                    if (isalnum((*position)) != 0)
                   4022:                    {
                   4023:                        break;
                   4024:                    }
                   4025: 
                   4026:                    position++;
                   4027:                }
                   4028: 
                   4029:                switch((*position))
                   4030:                {
                   4031:                    case 'N':
                   4032:                    {
1.66      bertrand 4033:                        tc.c_cflag &= ~((tcflag_t) PARENB);
1.46      bertrand 4034:                        break;
                   4035:                    }
                   4036: 
                   4037:                    case 'O':
                   4038:                    {
                   4039:                        tc.c_cflag |= PARENB;
                   4040:                        tc.c_cflag |= PARODD;
                   4041:                        break;
                   4042:                    }
                   4043: 
                   4044:                    case 'E':
                   4045:                    {
                   4046:                        tc.c_cflag |= PARENB;
1.66      bertrand 4047:                        tc.c_cflag &= ~((tcflag_t) PARODD);
1.46      bertrand 4048:                        break;
                   4049:                    }
                   4050: 
                   4051:                    default:
                   4052:                    {
                   4053:                        free(parametre_courant_majuscule);
                   4054:                        liberation(s_etat_processus, s_objet_argument);
                   4055:                        liberation(s_etat_processus, s_objet_resultat);
                   4056: 
                   4057:                        (*s_etat_processus).erreur_execution =
                   4058:                                d_ex_erreur_parametre_fichier;
                   4059:                        return;
                   4060:                    }
                   4061:                }
                   4062: 
1.49      bertrand 4063:                position++;
                   4064: 
1.46      bertrand 4065:                if ((*position) != d_code_espace)
                   4066:                {
                   4067:                    free(parametre_courant_majuscule);
                   4068:                    liberation(s_etat_processus, s_objet_argument);
                   4069:                    liberation(s_etat_processus, s_objet_resultat);
                   4070: 
                   4071:                    (*s_etat_processus).erreur_execution =
                   4072:                            d_ex_erreur_parametre_fichier;
                   4073:                    return;
                   4074:                }
                   4075: 
                   4076:                // Bits de stop
                   4077: 
                   4078:                while((*position) != d_code_fin_chaine)
                   4079:                {
                   4080:                    if (isalnum((*position)) != 0)
                   4081:                    {
                   4082:                        break;
                   4083:                    }
                   4084: 
                   4085:                    position++;
                   4086:                }
                   4087: 
                   4088:                switch((*position))
                   4089:                {
                   4090:                    case '1':
                   4091:                    {
1.66      bertrand 4092:                        tc.c_cflag &= ~((tcflag_t) CSTOPB);
1.46      bertrand 4093:                        break;
                   4094:                    }
                   4095: 
                   4096:                    case '2':
                   4097:                    {
                   4098:                        tc.c_cflag |= CSTOPB;
                   4099:                        break;
                   4100:                    }
                   4101: 
                   4102:                    default:
                   4103:                    {
                   4104:                        free(parametre_courant_majuscule);
                   4105:                        liberation(s_etat_processus, s_objet_argument);
                   4106:                        liberation(s_etat_processus, s_objet_resultat);
                   4107: 
                   4108:                        (*s_etat_processus).erreur_execution =
                   4109:                                d_ex_erreur_parametre_fichier;
                   4110:                        return;
                   4111:                    }
                   4112:                }
                   4113: 
                   4114:                // S'il reste autre chose que des espaces, il y a un
                   4115:                // problème de paramètres.
                   4116: 
1.49      bertrand 4117:                position++;
                   4118: 
1.46      bertrand 4119:                while((*position) != d_code_fin_chaine)
                   4120:                {
                   4121:                    if ((*position) != d_code_espace)
                   4122:                    {
                   4123:                        free(parametre_courant_majuscule);
                   4124:                        liberation(s_etat_processus, s_objet_argument);
                   4125:                        liberation(s_etat_processus, s_objet_resultat);
                   4126: 
                   4127:                        (*s_etat_processus).erreur_execution =
                   4128:                                d_ex_erreur_parametre_fichier;
                   4129:                        return;
                   4130:                    }
                   4131: 
                   4132:                    position++;
                   4133:                }
                   4134: 
                   4135:                // Autres paramètres
                   4136: 
                   4137:                free(parametre_courant_majuscule);
1.48      bertrand 4138:                parametre_courant = (*parametre_courant).suivant;
1.46      bertrand 4139: 
1.49      bertrand 4140:                if (parametre_courant != NULL)
                   4141:                {
                   4142:                    parametre_courant = (*(*parametre_courant).donnee).objet;
                   4143:                }
                   4144: 
1.46      bertrand 4145:                while(parametre_courant != NULL)
                   4146:                {
1.48      bertrand 4147:                    if ((*(*parametre_courant).donnee).type != CHN)
                   4148:                    {
                   4149:                        liberation(s_etat_processus, s_objet_argument);
                   4150:                        liberation(s_etat_processus, s_objet_resultat);
                   4151: 
                   4152:                        (*s_etat_processus).erreur_execution =
                   4153:                                d_ex_erreur_parametre_fichier;
                   4154:                        return;
                   4155:                    }
                   4156: 
                   4157:                    if ((parametre_courant_majuscule = conversion_majuscule(
1.80      bertrand 4158:                            s_etat_processus, (*(*parametre_courant).donnee)
                   4159:                            .objet)) == NULL)
1.48      bertrand 4160:                    {
                   4161:                        (*s_etat_processus).erreur_systeme =
                   4162:                                d_es_allocation_memoire;
                   4163:                        return;
                   4164:                    }
                   4165: 
                   4166:                    position = parametre_courant_majuscule;
                   4167:                    negation = d_faux;
                   4168: 
                   4169:                    unsigned char   *fonctions[] =
                   4170:                            { "IGNBRK", "BRKINT", "IGNPAR", "PARMRK",
                   4171:                            "INPCK", "ISTRIP", "INLCR", "IGNCR", "ICRNL",
1.57      bertrand 4172:                            "IXON",
                   4173: #ifdef IXANY
                   4174:                            "IXANY",
                   4175: #endif
                   4176:                            "IXOFF", "OPOST",
1.48      bertrand 4177:                            "ONLCR", "OCRNL", "ONOCR", "ONLRET",
1.57      bertrand 4178: #ifdef OFILL
                   4179:                            "OFILL",
                   4180: #endif
                   4181:                            "HUPCL", "CLOCAL",
                   4182: #ifdef CRTSCTS
                   4183:                            "CRTSCTS",
                   4184: #endif
1.48      bertrand 4185:                            "ISIG", "ICANON", "ECHO", "ECHOE", "ECHOK",
                   4186:                            "ECHONL", "NOFLSH", "TOSTOP", "IEXTEN", NULL };
1.66      bertrand 4187:                    tcflag_t        fonctions_constantes[] =
1.48      bertrand 4188:                            { /* c_iflag */
                   4189:                            1, IGNBRK, 1, BRKINT, 1, IGNPAR, 1, PARMRK,
                   4190:                            1, INPCK, 1, ISTRIP, 1, INLCR, 1, IGNCR, 1, ICRNL,
1.57      bertrand 4191:                            1, IXON,
                   4192: #ifdef IXANY
                   4193:                            1, IXANY,
                   4194: #endif
                   4195:                            1, IXOFF,
1.48      bertrand 4196:                            /* c_oflag */
                   4197:                            2 , OPOST, 2, ONLCR, 2, OCRNL, 2, ONOCR, 2, ONLRET,
1.57      bertrand 4198: #ifdef OFILL
                   4199:                            2, OFILL,
                   4200: #endif
                   4201:                            2, HUPCL,
1.48      bertrand 4202:                            /* c_cflag */
1.57      bertrand 4203:                            3, CLOCAL,
                   4204: #ifdef CRTSCTS
                   4205:                            3, CRTSCTS,
                   4206: #endif
1.48      bertrand 4207:                            /* c_lfkag */
                   4208:                            4, ISIG, 4, ICANON, 4, ECHO, 4, ECHOE, 4, ECHOK,
                   4209:                            4, ECHONL, 4, NOFLSH, 4, TOSTOP, 4, IEXTEN };
                   4210:                    unsigned int    fonction_courante;
                   4211: 
1.49      bertrand 4212:                    // On vient de trouver quelque chose à interpréter.
                   4213: 
                   4214:                    if (strncmp(position, "NO ", 3) == 0)
1.48      bertrand 4215:                    {
1.49      bertrand 4216:                        position += 3;
                   4217:                        negation = d_vrai;
1.48      bertrand 4218:                    }
                   4219: 
                   4220:                    for(fonction_courante = 0;
                   4221:                            fonctions[fonction_courante] != NULL;
                   4222:                            fonction_courante++)
                   4223:                    {
                   4224:                        if (strcmp(fonctions[fonction_courante], position)
                   4225:                                == 0)
                   4226:                        {
                   4227:                            if (negation == d_vrai)
                   4228:                            {
                   4229:                                switch(fonctions_constantes
                   4230:                                        [fonction_courante * 2])
                   4231:                                {
                   4232:                                    case 1:
                   4233:                                    {
                   4234:                                        tc.c_iflag &= ~fonctions_constantes
1.49      bertrand 4235:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4236:                                        break;
                   4237:                                    }
                   4238: 
                   4239:                                    case 2:
                   4240:                                    {
                   4241:                                        tc.c_oflag &= ~fonctions_constantes
1.49      bertrand 4242:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4243:                                        break;
                   4244:                                    }
                   4245: 
                   4246:                                    case 3:
                   4247:                                    {
                   4248:                                        tc.c_cflag &= ~fonctions_constantes
1.49      bertrand 4249:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4250:                                        break;
                   4251:                                    }
                   4252: 
                   4253:                                    case 4:
                   4254:                                    {
                   4255:                                        tc.c_lflag &= ~fonctions_constantes
1.49      bertrand 4256:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4257:                                        break;
                   4258:                                    }
                   4259:                                }
                   4260:                            }
                   4261:                            else
                   4262:                            {
                   4263:                                switch(fonctions_constantes
                   4264:                                        [fonction_courante * 2])
                   4265:                                {
                   4266:                                    case 1:
                   4267:                                    {
                   4268:                                        tc.c_iflag |= fonctions_constantes
1.49      bertrand 4269:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4270:                                        break;
                   4271:                                    }
                   4272: 
                   4273:                                    case 2:
                   4274:                                    {
                   4275:                                        tc.c_oflag |= fonctions_constantes
1.49      bertrand 4276:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4277:                                        break;
                   4278:                                    }
                   4279: 
                   4280:                                    case 3:
                   4281:                                    {
                   4282:                                        tc.c_cflag |= fonctions_constantes
1.49      bertrand 4283:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4284:                                        break;
                   4285:                                    }
                   4286: 
                   4287:                                    case 4:
                   4288:                                    {
                   4289:                                        tc.c_lflag |= fonctions_constantes
1.49      bertrand 4290:                                                [(fonction_courante * 2) + 1];
1.48      bertrand 4291:                                        break;
                   4292:                                    }
                   4293:                                }
                   4294:                            }
                   4295: 
                   4296:                            break;
                   4297:                        }
                   4298:                    }
                   4299: 
                   4300:                    if (fonctions[fonction_courante] == NULL)
                   4301:                    {
                   4302:                        free(parametre_courant_majuscule);
                   4303:                        liberation(s_etat_processus, s_objet_argument);
                   4304:                        liberation(s_etat_processus, s_objet_resultat);
                   4305: 
                   4306:                        (*s_etat_processus).erreur_execution =
                   4307:                                d_ex_erreur_parametre_fichier;
                   4308:                        return;
                   4309:                    }
                   4310: 
                   4311:                    free(parametre_courant_majuscule);
1.46      bertrand 4312:                    parametre_courant = (*parametre_courant).suivant;
                   4313:                }
1.47      bertrand 4314: 
                   4315:                if (tcsetattr(fileno(descripteur), TCSANOW, &tc) != 0)
                   4316:                {
                   4317:                    liberation(s_etat_processus, s_objet_argument);
                   4318:                    liberation(s_etat_processus, s_objet_resultat);
                   4319: 
                   4320:                    (*s_etat_processus).erreur_systeme =
                   4321:                            d_ex_erreur_fichier;
                   4322:                    return;
                   4323:                }
1.45      bertrand 4324:            }
                   4325: 
1.1       bertrand 4326:            strcpy((*((struct_fichier *) (*s_objet_resultat).objet)).nom, nom);
                   4327:            liberation(s_etat_processus, s_objet_argument);
                   4328: 
                   4329:            (*((struct_fichier *) (*s_objet_resultat).objet)).protection =
                   4330:                    protection;
                   4331:            (*((struct_fichier *) (*s_objet_resultat).objet)).position_clef =
                   4332:                    position_clef;
                   4333:            
                   4334:            rewind(descripteur);
                   4335: 
                   4336:            lock.l_type = F_WRLCK;
                   4337:            lock.l_whence = SEEK_SET;
                   4338:            lock.l_start = 0;
                   4339:            lock.l_len = 0;
                   4340:            lock.l_pid = getpid();
                   4341: 
                   4342:            if (fcntl(fileno(descripteur), F_GETLK, &lock) == -1)
                   4343:            {
                   4344:                if (fclose(descripteur) != 0)
                   4345:                {
                   4346:                    liberation(s_etat_processus, s_objet_resultat);
                   4347: 
1.6       bertrand 4348:                    (*s_etat_processus).erreur_systeme =
                   4349:                            d_es_erreur_fichier;
1.1       bertrand 4350:                    return;
                   4351:                }
                   4352: 
                   4353:                liberation(s_etat_processus, s_objet_resultat);
                   4354: 
                   4355:                (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   4356:                return;
                   4357:            }
                   4358: 
                   4359:            if (lock.l_type == F_UNLCK)
                   4360:            {
                   4361:                /*
                   4362:                 * Positionnement d'un verrou exclusif d'écriture par défaut
                   4363:                 */
                   4364: 
                   4365:                lock.l_type = F_RDLCK;
                   4366:                lock.l_whence = SEEK_SET;
                   4367:                lock.l_start = 0;
                   4368:                lock.l_len = 0;
                   4369:                lock.l_pid = getpid();
                   4370: 
                   4371:                if (fcntl(fileno(descripteur), F_SETLK, &lock) == -1)
                   4372:                {
                   4373:                    if (fclose(descripteur) != 0)
                   4374:                    {
                   4375:                        liberation(s_etat_processus, s_objet_resultat);
                   4376: 
                   4377:                        (*s_etat_processus).erreur_systeme =
                   4378:                                d_es_erreur_fichier;
                   4379:                        return;
                   4380:                    }
                   4381: 
                   4382:                    liberation(s_etat_processus, s_objet_resultat);
                   4383: 
1.6       bertrand 4384:                    (*s_etat_processus).erreur_systeme =
                   4385:                            d_es_erreur_fichier;
1.1       bertrand 4386:                    return;
                   4387:                }
                   4388:            }
                   4389:            else
                   4390:            {
                   4391:                /*
                   4392:                 * Test de la cohérence du verrou avec l'option PROTECTION
                   4393:                 */
                   4394: 
                   4395:                if ((lock.l_type == F_RDLCK) && (protection != 'R'))
                   4396:                {
1.6       bertrand 4397:                    free(nom);
                   4398: 
1.1       bertrand 4399:                    if (fclose(descripteur) != 0)
                   4400:                    {
                   4401:                        liberation(s_etat_processus, s_objet_resultat);
                   4402: 
                   4403:                        (*s_etat_processus).erreur_systeme =
                   4404:                                d_es_erreur_fichier;
                   4405:                        return;
                   4406:                    }
                   4407: 
                   4408:                    liberation(s_etat_processus, s_objet_resultat);
                   4409: 
                   4410:                    (*s_etat_processus).erreur_execution =
                   4411:                            d_ex_fichier_verrouille;
                   4412:                    return;
                   4413:                }
                   4414:                else if ((lock.l_type == F_WRLCK) && (protection != 'W'))
                   4415:                {
1.6       bertrand 4416:                    free(nom);
                   4417: 
1.1       bertrand 4418:                    if (fclose(descripteur) != 0)
                   4419:                    {
                   4420:                        liberation(s_etat_processus, s_objet_resultat);
                   4421: 
                   4422:                        (*s_etat_processus).erreur_systeme =
                   4423:                                d_es_erreur_fichier;
                   4424:                        return;
                   4425:                    }
                   4426: 
                   4427:                    liberation(s_etat_processus, s_objet_resultat);
                   4428: 
                   4429:                    (*s_etat_processus).erreur_execution =
                   4430:                            d_ex_fichier_verrouille;
                   4431:                    return;
                   4432:                }
                   4433:                else
                   4434:                {
1.6       bertrand 4435:                    free(nom);
                   4436: 
                   4437:                    if (fclose(descripteur) != 0)
                   4438:                    {
                   4439:                        liberation(s_etat_processus, s_objet_resultat);
                   4440: 
                   4441:                        (*s_etat_processus).erreur_systeme =
                   4442:                                d_es_erreur_fichier;
                   4443:                        return;
                   4444:                    }
                   4445: 
1.1       bertrand 4446:                    liberation(s_etat_processus, s_objet_resultat);
                   4447: 
                   4448:                    (*s_etat_processus).erreur_execution =
                   4449:                            d_ex_fichier_verrouille;
                   4450:                    return;
                   4451:                }
                   4452:            }
                   4453: 
                   4454:            /*
                   4455:             * Gestion de la liste des fichiers ouverts
                   4456:             */
                   4457: 
                   4458:            l_element_courant = (*s_etat_processus).s_fichiers;
                   4459: 
                   4460:            if (l_element_courant == NULL)
                   4461:            {
                   4462:                if (((*s_etat_processus).s_fichiers = malloc(sizeof(
                   4463:                        struct_liste_chainee))) == NULL)
                   4464:                {
                   4465:                    (*s_etat_processus).erreur_systeme =
                   4466:                            d_es_allocation_memoire;
                   4467:                    return;
                   4468:                }
                   4469: 
                   4470:                (*(*s_etat_processus).s_fichiers).suivant = NULL;
                   4471: 
                   4472:                if (((*(*s_etat_processus).s_fichiers).donnee =
                   4473:                        malloc(sizeof(struct_descripteur_fichier))) == NULL)
                   4474:                {
                   4475:                    (*s_etat_processus).erreur_systeme =
                   4476:                            d_es_allocation_memoire;
                   4477:                    return;
                   4478:                }
                   4479: 
                   4480:                l_element_courant = (*s_etat_processus).s_fichiers;
                   4481:                prochain_descripteur = 0;
                   4482:            }
                   4483:            else
                   4484:            {
                   4485:                /*
                   4486:                 * Recherche du premier descripteur libre
                   4487:                 */
                   4488: 
1.6       bertrand 4489:                if ((chaine_descripteurs = malloc(sizeof(unsigned char) *
                   4490:                        (ds_nombre_maximum_fichiers_ouverts + 1))) == NULL)
1.1       bertrand 4491:                {
                   4492:                    (*s_etat_processus).erreur_systeme =
                   4493:                            d_es_allocation_memoire;
                   4494:                    return;
                   4495:                }
                   4496: 
                   4497:                for(pointeur = chaine_descripteurs, i = 0;
                   4498:                        i < ds_nombre_maximum_fichiers_ouverts;
                   4499:                        (*pointeur) = d_code_espace, pointeur++, i++);
                   4500:                (*pointeur) = d_code_fin_chaine;
                   4501: 
                   4502:                do
                   4503:                {
                   4504:                    chaine_descripteurs[(*((struct_descripteur_fichier *)
                   4505:                            (*l_element_courant).donnee)).identifiant] = '-';
                   4506:                    l_element_courant = (*l_element_courant).suivant;
                   4507:                } while(l_element_courant != NULL);
                   4508: 
                   4509:                i = 0;
                   4510:                pointeur = chaine_descripteurs;
                   4511: 
                   4512:                while(i < ds_nombre_maximum_fichiers_ouverts)
                   4513:                {
                   4514:                    if ((*pointeur) == ' ')
                   4515:                    {
                   4516:                        break;
                   4517:                    }
                   4518: 
                   4519:                    pointeur++;
                   4520:                    i++;
                   4521:                }
                   4522: 
                   4523:                free(chaine_descripteurs);
                   4524: 
                   4525:                if (i == ds_nombre_maximum_fichiers_ouverts)
                   4526:                {
                   4527:                    (*s_etat_processus).erreur_systeme =
                   4528:                            d_es_nombre_max_descripteurs;
                   4529:                    return;
                   4530:                }
                   4531: 
1.67      bertrand 4532:                prochain_descripteur = (int) i;
1.1       bertrand 4533: 
                   4534:                /*
                   4535:                 * Ajout d'un élément à la fin de la liste chaînée
                   4536:                 */
                   4537: 
                   4538:                l_element_courant = (*s_etat_processus).s_fichiers;
                   4539:                while((*l_element_courant).suivant != NULL)
                   4540:                {
                   4541:                    l_element_courant = (*l_element_courant).suivant;
                   4542:                }
                   4543: 
                   4544:                if (((*l_element_courant).suivant =
                   4545:                        allocation_maillon(s_etat_processus)) == NULL)
                   4546:                {
                   4547:                    (*s_etat_processus).erreur_systeme =
                   4548:                            d_es_allocation_memoire;
                   4549:                    return;
                   4550:                }
                   4551: 
                   4552:                l_element_courant = (*l_element_courant).suivant;
                   4553:                (*l_element_courant).suivant = NULL;
                   4554: 
                   4555:                if (((*l_element_courant).donnee =
                   4556:                        malloc(sizeof(struct_descripteur_fichier))) == NULL)
                   4557:                {
                   4558:                    (*s_etat_processus).erreur_systeme =
                   4559:                            d_es_allocation_memoire;
                   4560:                    return;
                   4561:                }
                   4562:            }
                   4563: 
                   4564:            (*((struct_fichier *) (*s_objet_resultat).objet)).descripteur
                   4565:                    = prochain_descripteur;
                   4566:            (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4567:                    .identifiant = prochain_descripteur;
1.6       bertrand 4568: 
                   4569:            if (type_acces == 'S')
                   4570:            {
                   4571:                (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4572:                        .type = 'C';
                   4573:                (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4574:                        .descripteur_c = descripteur;
                   4575:            }
                   4576:            else
                   4577:            {
                   4578:                (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4579:                        .type = 'S';
                   4580:                (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4581:                        .descripteur_c = descripteur;
                   4582:                (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4583:                        .descripteur_sqlite = sqlite;
                   4584:            }
                   4585: 
1.1       bertrand 4586:            (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4587:                    .pid = getpid();
                   4588:            (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4589:                    .tid = pthread_self();
                   4590:            (*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                   4591:                    .effacement = (type_ouverture == 'S') ? 'Y' : 'N';
                   4592: 
1.6       bertrand 4593:            (*((struct_descripteur_fichier *) (*l_element_courant)
                   4594:                    .donnee)).nom = nom;
1.1       bertrand 4595:        }
                   4596:        else if (type_arguments == 'S')
                   4597:        {
                   4598:            /*
                   4599:             * Traitement des sockets
                   4600:             */
                   4601: 
                   4602:            /*
                   4603:             * Vérification de la cohérence des arguments et traitement
                   4604:             * des valeurs par défaut.
                   4605:             */
                   4606: 
                   4607:            if (format == ' ')
                   4608:            {
                   4609:                format = 'N';
                   4610:            }
                   4611: 
                   4612:            if (protection == ' ')
                   4613:            {
                   4614:                protection = 'N';
                   4615:            }
                   4616: 
                   4617:            if (type_domaine == ' ')
                   4618:            {
                   4619:                type_domaine = 'L';
                   4620:            }
                   4621: 
                   4622:            if (type_socket == ' ')
                   4623:            {
                   4624:                type_socket = 'S';
                   4625:                type = SOCK_STREAM;
                   4626:            }
                   4627: 
                   4628:            if (nom != NULL)
                   4629:            {
                   4630:                if (strcmp(protocole, "") == 0)
                   4631:                {
                   4632:                    strcpy(protocole, "UNIX");
                   4633:                }
                   4634:            }
                   4635:            else
                   4636:            {
                   4637:                if (strcmp(protocole, "") == 0)
                   4638:                {
                   4639:                    strcpy(protocole, "IPV4");
                   4640:                }
                   4641:            }
                   4642: 
                   4643:            if ((nom != NULL) && (hote != NULL))
                   4644:            {
                   4645:                liberation(s_etat_processus, s_objet_argument);
                   4646: 
                   4647:                (*s_etat_processus).erreur_execution =
                   4648:                        d_ex_erreur_parametre_fichier;
                   4649:                return;
                   4650:            }
                   4651: 
                   4652:            if ((nom != NULL) && (strcmp(protocole, "UNIX") != 0))
                   4653:            {
                   4654:                liberation(s_etat_processus, s_objet_argument);
                   4655: 
                   4656:                (*s_etat_processus).erreur_execution =
                   4657:                        d_ex_erreur_parametre_fichier;
                   4658:                return;
                   4659:            }
                   4660: 
                   4661:            if ((hote != NULL) && (strcmp(protocole, "UNIX") == 0))
                   4662:            {
                   4663:                liberation(s_etat_processus, s_objet_argument);
                   4664: 
                   4665:                (*s_etat_processus).erreur_execution =
                   4666:                        d_ex_erreur_parametre_fichier;
                   4667:                return;
                   4668:            }
                   4669: 
                   4670:            if ((nom != NULL) && (type_domaine == 'F') && (type_adresse != ' '))
                   4671:            {
                   4672:                liberation(s_etat_processus, s_objet_argument);
                   4673: 
                   4674:                (*s_etat_processus).erreur_execution =
                   4675:                        d_ex_erreur_parametre_fichier;
                   4676:                return;
                   4677:            }
                   4678: 
                   4679:            if ((presence_port == d_vrai) && (nom != NULL))
                   4680:            {
                   4681:                liberation(s_etat_processus, s_objet_argument);
                   4682: 
                   4683:                (*s_etat_processus).erreur_execution =
                   4684:                        d_ex_erreur_parametre_fichier;
                   4685:                return;
                   4686:            }
                   4687: 
1.42      bertrand 4688:            if ((type_adresse == ' ') && (type_domaine == 'L'))
                   4689:            {
                   4690:                if (strcmp(protocole, "IPV4") == 0)
                   4691:                {
                   4692:                    for(i = 0; i < 4; adresse[i++] = 0);
                   4693:                    type_adresse = '4';
                   4694:                }
                   4695:                else if (strcmp(protocole, "IPV6") == 0)
                   4696:                {
                   4697:                    for(i = 0; i < 16; adresse[i++] = 0);
                   4698:                    type_adresse = '6';
                   4699:                }
1.65      bertrand 4700:                else if (strcmp(protocole, "UNIX") != 0)
1.42      bertrand 4701:                {
                   4702:                    liberation(s_etat_processus, s_objet_argument);
                   4703: 
                   4704:                    (*s_etat_processus).erreur_execution =
                   4705:                            d_ex_erreur_parametre_fichier;
                   4706:                    return;
                   4707:                }
                   4708:            }
                   4709: 
1.1       bertrand 4710:            if (((strcmp(protocole, "IPV4") == 0) && (type_adresse == '6')) ||
                   4711:                    ((strcmp(protocole, "IPV6") == 0) && (type_adresse == '4')))
                   4712:            {
                   4713:                liberation(s_etat_processus, s_objet_argument);
                   4714: 
                   4715:                (*s_etat_processus).erreur_execution =
                   4716:                        d_ex_erreur_parametre_fichier;
                   4717:                return;
                   4718:            }
                   4719: 
                   4720:            if ((nombre_maximal_connexions != 0) && ((type_socket != 'S') &&
                   4721:                    (type_socket != 'Q')))
                   4722:            {
                   4723:                liberation(s_etat_processus, s_objet_argument);
                   4724: 
                   4725:                (*s_etat_processus).erreur_execution =
                   4726:                        d_ex_erreur_parametre_fichier;
                   4727:                return;
                   4728:            }
                   4729: 
                   4730:            if (nombre_maximal_connexions == 0)
                   4731:            {
                   4732:                nombre_maximal_connexions = 1;
                   4733:            }
                   4734: 
                   4735:            if (protocole_socket == NULL)
                   4736:            {
                   4737:                protocole_numerique = 0;
                   4738:            }
                   4739:            else
                   4740:            {
1.42      bertrand 4741:                if (strcmp(protocole_socket, "IPV4") == 0)
1.1       bertrand 4742:                {
                   4743:                    protocole_socket[2] = d_code_fin_chaine;
1.58      bertrand 4744:                    protocole_numerique = 0;
1.1       bertrand 4745:                }
1.58      bertrand 4746:                else
                   4747:                {
                   4748:                    if ((s_protocole = getprotobyname(protocole_socket))
                   4749:                            == NULL)
                   4750:                    {
                   4751:                        liberation(s_etat_processus, s_objet_argument);
1.1       bertrand 4752: 
1.58      bertrand 4753:                        (*s_etat_processus).erreur_execution =
                   4754:                                d_ex_erreur_parametre_fichier;
                   4755:                        return;
                   4756:                    }
1.1       bertrand 4757: 
1.58      bertrand 4758:                    protocole_numerique = (*s_protocole).p_proto;
1.1       bertrand 4759:                }
                   4760:            }
                   4761: 
                   4762:            if ((s_objet_resultat = allocation(s_etat_processus, SCK))
                   4763:                    == NULL)
                   4764:            {
                   4765:                (*s_etat_processus).erreur_systeme =
                   4766:                        d_es_allocation_memoire;
                   4767:                return;
                   4768:            }
                   4769: 
                   4770:            if (((*((struct_socket *) (*s_objet_resultat).objet)).format =
                   4771:                    allocation(s_etat_processus, LST)) == NULL)
                   4772:            {
                   4773:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   4774:                return;
                   4775:            }
                   4776: 
                   4777:            (*((struct_socket *) (*s_objet_resultat).objet)).protection
                   4778:                    = protection;
                   4779:            (*(*((struct_socket *) (*s_objet_resultat).objet))
                   4780:                    .format).objet = NULL;
1.51      bertrand 4781:            (*((struct_socket *) (*s_objet_resultat).objet)).adresse = NULL;
1.1       bertrand 4782: 
                   4783:            switch(type_socket)
                   4784:            {
                   4785:                case 'S' :
                   4786:                    type = SOCK_STREAM;
                   4787:                    strcpy((*((struct_socket *) (*s_objet_resultat).objet)).
                   4788:                            type, "STREAM");
                   4789:                    break;
                   4790: 
                   4791:                case 'D' :
                   4792:                    type = SOCK_DGRAM;
                   4793:                    strcpy((*((struct_socket *) (*s_objet_resultat).objet)).
                   4794:                            type, "DATAGRAM");
                   4795:                    break;
                   4796: 
                   4797:                case 'Q' :
                   4798:                    strcpy((*((struct_socket *) (*s_objet_resultat).objet)).
                   4799:                            type, "SEQUENTIAL DATAGRAM");
                   4800:                    type = SOCK_SEQPACKET;
                   4801:                    break;
                   4802: 
                   4803:                case 'R' :
                   4804:                    type = SOCK_RAW;
                   4805:                    strcpy((*((struct_socket *) (*s_objet_resultat).objet)).
                   4806:                            type, "RAW");
                   4807:                    break;
                   4808: 
                   4809:                case 'M' :
                   4810:                    type = SOCK_RDM;
                   4811:                    strcpy((*((struct_socket *) (*s_objet_resultat).objet)).
                   4812:                            type, "ROBUST DATAGRAM");
                   4813:                    break;
1.10      bertrand 4814: 
                   4815:                default :
                   4816:                    BUG(1, printf("type_socket=%c\n", type_socket));
                   4817:                    break;
1.1       bertrand 4818:            }
                   4819: 
                   4820:            if ((protection != 'N') && ((type_socket != 'S') &&
                   4821:                    (type_socket != 'Q')))
                   4822:            {
                   4823:                liberation(s_etat_processus, s_objet_argument);
                   4824:                liberation(s_etat_processus, s_objet_resultat);
                   4825: 
                   4826:                (*s_etat_processus).erreur_execution =
                   4827:                        d_ex_erreur_parametre_fichier;
                   4828:                return;
                   4829:            }
                   4830: 
                   4831:            if (nom == NULL)
                   4832:            {
                   4833:                if (((*((struct_socket *) (*s_objet_resultat).objet)).adresse =
                   4834:                        malloc(sizeof(unsigned char))) == NULL)
                   4835:                {
                   4836:                    (*s_etat_processus).erreur_systeme =
                   4837:                            d_es_allocation_memoire;
                   4838:                    return;
                   4839:                }
                   4840: 
                   4841:                strcpy((*((struct_socket *) (*s_objet_resultat).objet)).adresse,
                   4842:                        "");
                   4843:            }
                   4844:            else
                   4845:            {
                   4846:                if (((*((struct_socket *) (*s_objet_resultat).objet)).adresse =
1.6       bertrand 4847:                        transliteration(s_etat_processus, nom,
                   4848:                        d_locale, "UTF-8")) == NULL)
1.1       bertrand 4849:                {
1.6       bertrand 4850:                    liberation(s_etat_processus, s_objet_argument);
                   4851:                    liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 4852:                    return;
                   4853:                }
                   4854:            }
                   4855: 
                   4856:            if (((*((struct_socket *) (*s_objet_resultat).objet))
                   4857:                    .adresse_distante = malloc(sizeof(unsigned char))) == NULL)
                   4858:            {
                   4859:                (*s_etat_processus).erreur_systeme =
                   4860:                        d_es_allocation_memoire;
                   4861:                return;
                   4862:            }
                   4863: 
                   4864:            strcpy((*((struct_socket *) (*s_objet_resultat).objet))
                   4865:                    .adresse_distante, "");
                   4866: 
                   4867:            (*((struct_socket *) (*s_objet_resultat).objet)).localisation =
                   4868:                    type_domaine;
                   4869:            (*((struct_socket *) (*s_objet_resultat).objet)).binaire =
                   4870:                    format;
                   4871:            (*((struct_socket *) (*s_objet_resultat).objet)).pid =
                   4872:                    getpid();
                   4873:            (*((struct_socket *) (*s_objet_resultat).objet)).tid =
                   4874:                    pthread_self();
                   4875:            (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
                   4876:                    = 'Y';
                   4877:            (*((struct_socket *) (*s_objet_resultat).objet)).socket_connectee
                   4878:                    = d_faux;
1.84      bertrand 4879:            (*((struct_socket *) (*s_objet_resultat).objet)).options = 0;
1.1       bertrand 4880: 
                   4881:            if (type_domaine == 'L')
                   4882:            { // Socket serveur
                   4883:                if (nom != NULL)
                   4884:                {
                   4885:                    /*
                   4886:                     * La socket locale est dans l'espace des noms.
                   4887:                     */
                   4888: 
                   4889:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   4890:                            .socket = socket(PF_UNIX, type,
                   4891:                            protocole_numerique)) == -1)
                   4892:                    {
                   4893:                        liberation(s_etat_processus, s_objet_argument);
                   4894:                        liberation(s_etat_processus, s_objet_resultat);
                   4895: 
                   4896:                        (*s_etat_processus).erreur_execution =
                   4897:                                d_ex_erreur_acces_fichier;
                   4898:                        return;
                   4899:                    }
                   4900: 
                   4901:                    (*((struct_socket *) (*s_objet_resultat).objet)).domaine
                   4902:                            = PF_UNIX;
                   4903:                    (*((struct_socket *) (*s_objet_resultat).objet)).effacement
                   4904:                            = 'Y';
                   4905: 
                   4906:                    socket_unix.sun_family = AF_UNIX;
                   4907: 
                   4908:                    pointeur = (*((struct_socket *)
                   4909:                            (*s_objet_resultat).objet)).adresse;
                   4910: 
                   4911:                    while((*pointeur) == d_code_espace)
                   4912:                    {
                   4913:                        pointeur++;
                   4914:                    }
                   4915: 
1.21      bertrand 4916:                    strncpy(socket_unix.sun_path, pointeur, UNIX_PATH_MAX);
                   4917:                    socket_unix.sun_path[UNIX_PATH_MAX - 1] = d_code_fin_chaine;
1.1       bertrand 4918: 
1.82      bertrand 4919:                    if (options_socket(s_etat_processus, s_objet_resultat,
                   4920:                            options, peripherique, &priorite,
                   4921:                            &buffer_emission, &buffer_reception,
                   4922:                            &timeout_emission, &timeout_reception) == d_erreur)
1.1       bertrand 4923:                    {
                   4924:                        liberation(s_etat_processus, s_objet_argument);
                   4925:                        liberation(s_etat_processus, s_objet_resultat);
                   4926: 
                   4927:                        return;
                   4928:                    }
                   4929: 
                   4930:                    if (bind((*((struct_socket *) (*s_objet_resultat).objet))
                   4931:                            .socket, (const struct sockaddr *) &socket_unix,
                   4932:                            sizeof(socket_unix)) != 0)
                   4933:                    {
                   4934:                        liberation(s_etat_processus, s_objet_argument);
                   4935:                        liberation(s_etat_processus, s_objet_resultat);
                   4936: 
                   4937:                        (*s_etat_processus).erreur_execution =
                   4938:                                d_ex_erreur_acces_fichier;
                   4939:                        return;
                   4940:                    }
                   4941:                }
                   4942:                else
                   4943:                {
                   4944:                    /*
                   4945:                     * La socket est une socket réseau locale. L'adresse
                   4946:                     * passée en argument est l'adresse sur laquelle
                   4947:                     * cette socket est à l'écoute.
                   4948:                     */
                   4949: 
                   4950:                    (*((struct_socket *) (*s_objet_resultat).objet)).effacement
                   4951:                            = 'N';
                   4952: 
                   4953:                    if (hote != NULL)
                   4954:                    { // Hôte défini par un nom
                   4955:                        resolution = NULL;
                   4956: 
                   4957:                        if (getaddrinfo(hote, NULL, NULL, &resolution) != 0) 
                   4958:                        {
                   4959:                            liberation(s_etat_processus, s_objet_argument);
                   4960:                            liberation(s_etat_processus, s_objet_resultat);
                   4961: 
                   4962:                            if (resolution != NULL)
                   4963:                            {
                   4964:                                freeaddrinfo(resolution);
                   4965:                            }
                   4966: 
                   4967:                            (*s_etat_processus).erreur_execution =
                   4968:                                    d_ex_erreur_acces_fichier;
                   4969:                            return;
                   4970:                        }
                   4971: 
                   4972:                        if (strcmp(protocole, "IPV4") == 0)
                   4973:                        { // Accès en IPv4
                   4974:                            resolution_courante = resolution;
                   4975: 
                   4976:                            while(resolution_courante != NULL)
                   4977:                            {
                   4978:                                if ((*resolution_courante).ai_family ==
                   4979:                                        AF_INET)
                   4980:                                {
                   4981:                                    break;
                   4982:                                }
                   4983: 
                   4984:                                resolution_courante = (*resolution_courante)
                   4985:                                        .ai_next;
                   4986:                            }
                   4987: 
                   4988:                            if (resolution_courante == NULL)
                   4989:                            {
                   4990:                                liberation(s_etat_processus, s_objet_argument);
                   4991:                                liberation(s_etat_processus, s_objet_resultat);
                   4992: 
                   4993:                                freeaddrinfo(resolution);
                   4994: 
                   4995:                                (*s_etat_processus).erreur_execution =
                   4996:                                        d_ex_erreur_acces_fichier;
                   4997:                                return;
                   4998:                            }
                   4999: 
                   5000:                            if (((*((struct_socket *)
                   5001:                                    (*s_objet_resultat).objet))
                   5002:                                    .socket = socket(PF_INET, type,
                   5003:                                    protocole_numerique)) == -1)
                   5004:                            {
                   5005:                                liberation(s_etat_processus, s_objet_argument);
                   5006:                                liberation(s_etat_processus, s_objet_resultat);
                   5007: 
                   5008:                                freeaddrinfo(resolution);
                   5009: 
                   5010:                                (*s_etat_processus).erreur_execution =
                   5011:                                        d_ex_erreur_acces_fichier;
                   5012:                                return;
                   5013:                            }
                   5014: 
                   5015:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5016:                                    .domaine = PF_INET;
                   5017: 
                   5018:                            memset(&socket_ipv4, 0, sizeof(socket_ipv4));
                   5019:                            socket_ipv4.sin_family = AF_INET;
                   5020:                            socket_ipv4.sin_port = htons((uint16_t) port);
                   5021:                            socket_ipv4.sin_addr.s_addr =
                   5022:                                    (*((struct sockaddr_in *)
                   5023:                                    (*resolution_courante).ai_addr))
                   5024:                                    .sin_addr.s_addr;
                   5025: 
1.82      bertrand 5026:                            if (options_socket(s_etat_processus,
                   5027:                                    s_objet_resultat,
                   5028:                                    options, peripherique, &priorite,
                   5029:                                    &buffer_emission, &buffer_reception,
                   5030:                                    &timeout_emission, &timeout_reception)
                   5031:                                    == d_erreur)
1.1       bertrand 5032:                            {
                   5033:                                liberation(s_etat_processus, s_objet_argument);
                   5034:                                liberation(s_etat_processus, s_objet_resultat);
                   5035: 
                   5036:                                freeaddrinfo(resolution);
                   5037:                                return;
                   5038:                            }
                   5039: 
                   5040:                            if (bind((*((struct_socket *) (*s_objet_resultat)
                   5041:                                    .objet)).socket, (const struct sockaddr *)
                   5042:                                    &socket_ipv4, sizeof(socket_ipv4)) != 0)
                   5043:                            {
                   5044:                                liberation(s_etat_processus, s_objet_argument);
                   5045:                                liberation(s_etat_processus, s_objet_resultat);
                   5046: 
                   5047:                                freeaddrinfo(resolution);
                   5048: 
                   5049:                                (*s_etat_processus).erreur_execution =
                   5050:                                        d_ex_erreur_acces_fichier;
                   5051:                                return;
                   5052:                            }
                   5053: 
1.51      bertrand 5054:                            free((*((struct_socket *) (*s_objet_resultat)
                   5055:                                    .objet)).adresse);
                   5056: 
1.1       bertrand 5057:                            if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5058:                                    .objet)).adresse = malloc(23 *
1.1       bertrand 5059:                                    sizeof(unsigned char))) == NULL)
                   5060:                            {
                   5061:                                (*s_etat_processus).erreur_systeme =
                   5062:                                        d_es_allocation_memoire;
                   5063:                                return;
                   5064:                            }
                   5065: 
                   5066:                            sprintf((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5067:                                    .objet)).adresse, "%d.%d.%d.%d(%u)",
1.1       bertrand 5068:                                    (ntohl((*((struct sockaddr_in *)
                   5069:                                    (*resolution_courante).ai_addr)).sin_addr
                   5070:                                    .s_addr) >> 24) & 0xFF,
                   5071:                                    (ntohl((*((struct sockaddr_in *)
                   5072:                                    (*resolution_courante).ai_addr)).sin_addr
                   5073:                                    .s_addr) >> 16) & 0xFF,
                   5074:                                    (ntohl((*((struct sockaddr_in *)
                   5075:                                    (*resolution_courante).ai_addr)).sin_addr
                   5076:                                    .s_addr) >> 8) & 0xFF,
                   5077:                                    ntohl((*((struct sockaddr_in *)
                   5078:                                    (*resolution_courante).ai_addr)).sin_addr
1.94      bertrand 5079:                                    .s_addr) & 0xFF,
                   5080:                                    (unsigned int) port);
1.1       bertrand 5081:                        }
                   5082:                        else
                   5083:                        { // Accès en IPv6
1.17      bertrand 5084: #                          ifdef IPV6
1.1       bertrand 5085:                            resolution_courante = resolution;
                   5086: 
                   5087:                            while(resolution_courante != NULL)
                   5088:                            {
                   5089:                                if ((*resolution_courante).ai_family ==
                   5090:                                        AF_INET6)
                   5091:                                {
                   5092:                                    break;
                   5093:                                }
                   5094: 
                   5095:                                resolution_courante = (*resolution_courante)
                   5096:                                        .ai_next;
                   5097:                            }
                   5098: 
                   5099:                            if (resolution_courante == NULL)
                   5100:                            {
                   5101:                                liberation(s_etat_processus, s_objet_argument);
                   5102:                                liberation(s_etat_processus, s_objet_resultat);
                   5103: 
                   5104:                                freeaddrinfo(resolution);
                   5105: 
                   5106:                                (*s_etat_processus).erreur_execution =
                   5107:                                        d_ex_erreur_acces_fichier;
                   5108:                                return;
                   5109:                            }
                   5110: 
                   5111:                            if (((*((struct_socket *)
                   5112:                                    (*s_objet_resultat).objet))
                   5113:                                    .socket = socket(PF_INET6, type,
                   5114:                                    protocole_numerique)) == -1)
                   5115:                            {
                   5116:                                liberation(s_etat_processus, s_objet_argument);
                   5117:                                liberation(s_etat_processus, s_objet_resultat);
                   5118: 
                   5119:                                freeaddrinfo(resolution);
                   5120: 
                   5121:                                (*s_etat_processus).erreur_execution =
                   5122:                                        d_ex_erreur_acces_fichier;
                   5123:                                return;
                   5124:                            }
                   5125: 
                   5126:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5127:                                    .domaine = PF_INET6;
                   5128: 
                   5129:                            memset(&socket_ipv6, 0, sizeof(socket_ipv6));
                   5130:                            socket_ipv6.sin6_family = AF_INET6;
                   5131:                            socket_ipv6.sin6_port = htons((uint16_t) port);
                   5132: 
                   5133:                            for(i = 0; i < 16;
                   5134:                                    socket_ipv6.sin6_addr.s6_addr[i] =
                   5135:                                    (*((struct sockaddr_in6 *)
                   5136:                                    (*resolution_courante).ai_addr))
                   5137:                                    .sin6_addr.s6_addr[i], i++);
                   5138: 
1.82      bertrand 5139:                            if (options_socket(s_etat_processus,
                   5140:                                    s_objet_resultat,
                   5141:                                    options, peripherique, &priorite,
                   5142:                                    &buffer_emission, &buffer_reception,
                   5143:                                    &timeout_emission, &timeout_reception)
                   5144:                                    == d_erreur)
1.1       bertrand 5145:                            {
                   5146:                                liberation(s_etat_processus, s_objet_argument);
                   5147:                                liberation(s_etat_processus, s_objet_resultat);
                   5148: 
                   5149:                                freeaddrinfo(resolution);
                   5150:                                return;
                   5151:                            }
                   5152: 
                   5153:                            if (bind((*((struct_socket *) (*s_objet_resultat)
                   5154:                                    .objet)).socket, (const struct sockaddr *)
                   5155:                                    &socket_ipv6, sizeof(socket_ipv6)) != 0)
                   5156:                            {
                   5157:                                liberation(s_etat_processus, s_objet_argument);
                   5158:                                liberation(s_etat_processus, s_objet_resultat);
                   5159: 
                   5160:                                freeaddrinfo(resolution);
                   5161: 
                   5162:                                (*s_etat_processus).erreur_execution =
                   5163:                                        d_ex_erreur_acces_fichier;
                   5164:                                return;
                   5165:                            }
                   5166: 
1.51      bertrand 5167:                            free((*((struct_socket *) (*s_objet_resultat)
                   5168:                                    .objet)).adresse);
                   5169: 
1.94      bertrand 5170:                            /*
                   5171:                             * Longueur de la chaîne :
                   5172:                             * Adresse IPv6 : 16 octets soit 128 bits.
                   5173:                             * => 32 chiffres en hexadécimal
                   5174:                             * Par groupe de 4, 8 groupes
                   5175:                             * => 7 ":"
                   5176:                             * Port : (%u)
                   5177:                             * => 7
                   5178:                             * ==> 32 + 7 + 7 + 1 = 47
                   5179:                             */
                   5180: 
1.1       bertrand 5181:                            if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5182:                                    .objet)).adresse = malloc(47 *
1.1       bertrand 5183:                                    sizeof(unsigned char))) == NULL)
                   5184:                            {
                   5185:                                (*s_etat_processus).erreur_systeme =
                   5186:                                        d_es_allocation_memoire;
                   5187:                                return;
                   5188:                            }
                   5189: 
1.94      bertrand 5190:                            sprintf((*((struct_socket *) (*s_objet_resultat)
                   5191:                                    .objet)).adresse,
                   5192:                                    "%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
                   5193:                                    "%02X%02X:%02X%02X:%02X%02X:%02X%02X(%u)",
                   5194:                                    (*((struct sockaddr_in6 *)
                   5195:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5196:                                    .s6_addr[0],
                   5197:                                    (*((struct sockaddr_in6 *)
                   5198:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5199:                                    .s6_addr[1],
                   5200:                                    (*((struct sockaddr_in6 *)
                   5201:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5202:                                    .s6_addr[2],
                   5203:                                    (*((struct sockaddr_in6 *)
                   5204:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5205:                                    .s6_addr[3],
                   5206:                                    (*((struct sockaddr_in6 *)
                   5207:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5208:                                    .s6_addr[4],
                   5209:                                    (*((struct sockaddr_in6 *)
                   5210:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5211:                                    .s6_addr[5],
                   5212:                                    (*((struct sockaddr_in6 *)
                   5213:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5214:                                    .s6_addr[6],
                   5215:                                    (*((struct sockaddr_in6 *)
                   5216:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5217:                                    .s6_addr[7],
                   5218:                                    (*((struct sockaddr_in6 *)
                   5219:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5220:                                    .s6_addr[8],
                   5221:                                    (*((struct sockaddr_in6 *)
                   5222:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5223:                                    .s6_addr[9],
                   5224:                                    (*((struct sockaddr_in6 *)
                   5225:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5226:                                    .s6_addr[10],
                   5227:                                    (*((struct sockaddr_in6 *)
                   5228:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5229:                                    .s6_addr[11],
                   5230:                                    (*((struct sockaddr_in6 *)
                   5231:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5232:                                    .s6_addr[12],
                   5233:                                    (*((struct sockaddr_in6 *)
                   5234:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5235:                                    .s6_addr[13],
                   5236:                                    (*((struct sockaddr_in6 *)
                   5237:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5238:                                    .s6_addr[14],
                   5239:                                    (*((struct sockaddr_in6 *)
                   5240:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5241:                                    .s6_addr[15],
                   5242:                                    (unsigned int) port);
1.17      bertrand 5243: #                          else
1.19      bertrand 5244:                            if ((*s_etat_processus).langue == 'F')
                   5245:                            {
                   5246:                                printf("+++Attention : Support du protocole"
1.20      bertrand 5247:                                        " IPv6 indisponible\n");
1.19      bertrand 5248:                            }
                   5249:                            else
                   5250:                            {
1.22      bertrand 5251:                                printf("+++Warning : IPv6 support "
1.19      bertrand 5252:                                        "unavailable\n");
                   5253:                            }
1.51      bertrand 5254: 
                   5255:                            liberation(s_etat_processus, s_objet_argument);
                   5256:                            liberation(s_etat_processus, s_objet_resultat);
                   5257: 
                   5258:                            freeaddrinfo(resolution);
                   5259: 
                   5260:                            (*s_etat_processus).erreur_execution =
                   5261:                                    d_ex_instruction_indisponible;
                   5262:                            return;
1.17      bertrand 5263: #                          endif
1.1       bertrand 5264:                        }
                   5265: 
                   5266:                        freeaddrinfo(resolution);
                   5267:                    }
                   5268:                    else
                   5269:                    { // Hôte défini par une adresse
                   5270:                        if (strcmp(protocole, "IPV4") == 0)
                   5271:                        { // Accès en IPv4
1.51      bertrand 5272:                            free((*((struct_socket *) (*s_objet_resultat)
                   5273:                                    .objet)).adresse);
                   5274: 
1.1       bertrand 5275:                            if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5276:                                    .objet)).adresse = malloc(23 *
1.1       bertrand 5277:                                    sizeof(unsigned char))) == NULL)
                   5278:                            {
                   5279:                                (*s_etat_processus).erreur_systeme =
                   5280:                                        d_es_allocation_memoire;
                   5281:                                return;
                   5282:                            }
                   5283: 
                   5284:                            sprintf((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5285:                                    .objet)).adresse, "%d.%d.%d.%d(%u)",
                   5286:                                    (int) adresse[0], (int) adresse[1],
                   5287:                                    (int) adresse[2], (int) adresse[3],
                   5288:                                    (unsigned int) port);
1.1       bertrand 5289: 
                   5290:                            if (((*((struct_socket *)
                   5291:                                    (*s_objet_resultat).objet))
                   5292:                                    .socket = socket(PF_INET, type,
                   5293:                                    protocole_numerique)) == -1)
                   5294:                            {
                   5295:                                liberation(s_etat_processus, s_objet_argument);
                   5296:                                liberation(s_etat_processus, s_objet_resultat);
                   5297: 
                   5298:                                (*s_etat_processus).erreur_execution =
                   5299:                                        d_ex_erreur_acces_fichier;
                   5300:                                return;
                   5301:                            }
                   5302: 
                   5303:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5304:                                    .domaine = PF_INET;
                   5305: 
                   5306:                            memset(&socket_ipv4, 0, sizeof(socket_ipv4));
                   5307:                            socket_ipv4.sin_family = AF_INET;
                   5308:                            socket_ipv4.sin_port = htons((uint16_t) port);
                   5309: 
                   5310:                            adresse_ipv4 = 0;
                   5311:                            for(i = 0; i < 4; adresse_ipv4 =
1.66      bertrand 5312:                                    (256 * adresse_ipv4) +
                   5313:                                    ((unsigned char) adresse[i++]));
1.1       bertrand 5314: 
                   5315:                            socket_ipv4.sin_addr.s_addr = htonl(adresse_ipv4);
                   5316: 
1.82      bertrand 5317:                            if (options_socket(s_etat_processus,
                   5318:                                    s_objet_resultat,
                   5319:                                    options, peripherique, &priorite,
                   5320:                                    &buffer_emission, &buffer_reception,
                   5321:                                    &timeout_emission, &timeout_reception)
                   5322:                                    == d_erreur)
1.1       bertrand 5323:                            {
                   5324:                                liberation(s_etat_processus, s_objet_argument);
                   5325:                                liberation(s_etat_processus, s_objet_resultat);
                   5326: 
                   5327:                                return;
                   5328:                            }
                   5329: 
                   5330:                            if (bind((*((struct_socket *) (*s_objet_resultat)
                   5331:                                    .objet)).socket, (const struct sockaddr *)
                   5332:                                    &socket_ipv4, sizeof(socket_ipv4)) != 0)
                   5333:                            {
                   5334:                                liberation(s_etat_processus, s_objet_argument);
                   5335:                                liberation(s_etat_processus, s_objet_resultat);
                   5336: 
                   5337:                                (*s_etat_processus).erreur_execution =
                   5338:                                        d_ex_erreur_acces_fichier;
                   5339:                                return;
                   5340:                            }
                   5341:                        }
                   5342:                        else
                   5343:                        { // Accès en IPv6
1.17      bertrand 5344: #                          ifdef IPV6
1.51      bertrand 5345:                            free((*((struct_socket *) (*s_objet_resultat)
                   5346:                                    .objet)).adresse);
                   5347: 
1.1       bertrand 5348:                            if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5349:                                    .objet)).adresse = malloc(47 *
1.1       bertrand 5350:                                    sizeof(unsigned char))) == NULL)
                   5351:                            {
                   5352:                                (*s_etat_processus).erreur_systeme =
                   5353:                                        d_es_allocation_memoire;
                   5354:                                return;
                   5355:                            }
                   5356: 
                   5357:                            sprintf((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5358:                                    .objet)).adresse,
                   5359:                                    "%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
                   5360:                                    "%02X%02X:%02X%02X:%02X%02X:%02X%02X(%u)",
                   5361:                                    (unsigned int) adresse[0],
                   5362:                                    (unsigned int) adresse[1],
                   5363:                                    (unsigned int) adresse[2],
                   5364:                                    (unsigned int) adresse[3],
                   5365:                                    (unsigned int) adresse[4],
                   5366:                                    (unsigned int) adresse[5],
                   5367:                                    (unsigned int) adresse[6],
                   5368:                                    (unsigned int) adresse[7],
                   5369:                                    (unsigned int) adresse[8],
                   5370:                                    (unsigned int) adresse[9],
                   5371:                                    (unsigned int) adresse[10],
                   5372:                                    (unsigned int) adresse[11],
                   5373:                                    (unsigned int) adresse[12],
                   5374:                                    (unsigned int) adresse[13],
                   5375:                                    (unsigned int) adresse[14],
                   5376:                                    (unsigned int) adresse[15],
                   5377:                                    (unsigned int) port);
1.1       bertrand 5378: 
                   5379:                            if (((*((struct_socket *)
                   5380:                                    (*s_objet_resultat).objet))
                   5381:                                    .socket = socket(PF_INET6, type,
                   5382:                                    protocole_numerique)) == -1)
                   5383:                            {
                   5384:                                liberation(s_etat_processus, s_objet_argument);
                   5385:                                liberation(s_etat_processus, s_objet_resultat);
                   5386: 
                   5387:                                (*s_etat_processus).erreur_execution =
                   5388:                                        d_ex_erreur_acces_fichier;
                   5389:                                return;
                   5390:                            }
                   5391: 
                   5392:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5393:                                    .domaine = PF_INET6;
                   5394: 
                   5395:                            memset(&socket_ipv6, 0, sizeof(socket_ipv6));
                   5396:                            socket_ipv6.sin6_family = AF_INET6;
                   5397:                            socket_ipv6.sin6_port = htons((uint16_t) port);
                   5398: 
                   5399:                            for(i = 0; i < 16;
                   5400:                                    socket_ipv6.sin6_addr.s6_addr[i] =
                   5401:                                    (unsigned char) (adresse[i]), i++);
                   5402: 
1.82      bertrand 5403:                            if (options_socket(s_etat_processus,
                   5404:                                    s_objet_resultat,
                   5405:                                    options, peripherique, &priorite,
                   5406:                                    &buffer_emission, &buffer_reception,
                   5407:                                    &timeout_emission, &timeout_reception)
                   5408:                                    == d_erreur)
1.1       bertrand 5409:                            {
                   5410:                                liberation(s_etat_processus, s_objet_argument);
                   5411:                                liberation(s_etat_processus, s_objet_resultat);
                   5412: 
                   5413:                                return;
                   5414:                            }
                   5415: 
                   5416:                            if (bind((*((struct_socket *) (*s_objet_resultat)
                   5417:                                    .objet)).socket, (const struct sockaddr *)
                   5418:                                    &socket_ipv6, sizeof(socket_ipv6)) != 0)
                   5419:                            {
                   5420:                                liberation(s_etat_processus, s_objet_argument);
                   5421:                                liberation(s_etat_processus, s_objet_resultat);
                   5422: 
                   5423:                                (*s_etat_processus).erreur_execution =
                   5424:                                        d_ex_erreur_acces_fichier;
                   5425:                                return;
                   5426:                            }
1.17      bertrand 5427: #                          else
1.19      bertrand 5428:                            if ((*s_etat_processus).langue == 'F')
                   5429:                            {
                   5430:                                printf("+++Attention : Support du protocole"
1.20      bertrand 5431:                                        " IPv6 indisponible\n");
1.19      bertrand 5432:                            }
                   5433:                            else
                   5434:                            {
1.22      bertrand 5435:                                printf("+++Warning : IPv6 support "
1.19      bertrand 5436:                                        "unavailable\n");
                   5437:                            }
1.51      bertrand 5438:                            
                   5439:                            liberation(s_etat_processus, s_objet_argument);
                   5440:                            liberation(s_etat_processus, s_objet_resultat);
                   5441: 
                   5442:                            (*s_etat_processus).erreur_execution =
                   5443:                                    d_ex_instruction_indisponible;
                   5444:                            return;
1.17      bertrand 5445: #                          endif
1.1       bertrand 5446:                        }
                   5447:                    }
                   5448: 
                   5449:                    (*((struct_socket *) (*s_objet_resultat).objet)).effacement
                   5450:                            = 'N';
                   5451:                }
                   5452: 
                   5453:                if ((type_socket == 'S') || (type_socket == 'Q'))
                   5454:                {
                   5455:                    if (listen((*((struct_socket *) (*s_objet_resultat).objet))
                   5456:                            .socket, (int) nombre_maximal_connexions) != 0)
                   5457:                    {
                   5458:                        liberation(s_etat_processus, s_objet_argument);
                   5459:                        liberation(s_etat_processus, s_objet_resultat);
                   5460: 
                   5461:                        (*s_etat_processus).erreur_execution =
                   5462:                                d_ex_erreur_acces_fichier;
                   5463:                        return;
                   5464:                    }
                   5465: 
                   5466:                    (*((struct_socket *) (*s_objet_resultat).objet))
                   5467:                            .socket_connectee = d_vrai;
                   5468: 
                   5469:                    if (protection == 'R')
                   5470:                    { // WRITEONLY
                   5471:                        if (shutdown((*((struct_socket *) (*s_objet_resultat)
                   5472:                                .objet)).socket, SHUT_RD) != 0)
                   5473:                        {
                   5474:                            liberation(s_etat_processus, s_objet_argument);
                   5475:                            liberation(s_etat_processus, s_objet_resultat);
                   5476: 
                   5477:                            (*s_etat_processus).erreur_execution =
                   5478:                                    d_ex_erreur_acces_fichier;
                   5479:                            return;
                   5480:                        }
                   5481:                    }
                   5482:                    else if (protection == 'W')
                   5483:                    { // READONLY
                   5484:                        if (shutdown((*((struct_socket *) (*s_objet_resultat)
                   5485:                                .objet)).socket, SHUT_WR) != 0)
                   5486:                        {
                   5487:                            liberation(s_etat_processus, s_objet_argument);
                   5488:                            liberation(s_etat_processus, s_objet_resultat);
                   5489: 
                   5490:                            (*s_etat_processus).erreur_execution =
                   5491:                                    d_ex_erreur_acces_fichier;
                   5492:                            return;
                   5493:                        }
                   5494:                    }
                   5495:                    else
                   5496:                    { // READWRITE
                   5497:                    }
                   5498:                }
                   5499:            }
                   5500:            else
                   5501:            { // Socket cliente
                   5502:                (*((struct_socket *) (*s_objet_resultat).objet)).effacement
                   5503:                        = 'N';
                   5504: 
                   5505:                /*
                   5506:                 * Dans le cas où la socket n'est pas connectée, on
                   5507:                 * ne peut utiliser ni "NAME", ni "HOST", ni "PORT",
                   5508:                 * et encore moins spécifier une adresse. En effet, la cible
                   5509:                 * est défini par la commande TARGET.
                   5510:                 */
                   5511: 
                   5512:                if ((type_socket != 'S') && (type_socket != 'Q'))
                   5513:                {
                   5514:                    if ((presence_port == d_vrai) || (hote != NULL) ||
                   5515:                            (nom != NULL) || (type_adresse != ' '))
                   5516:                    {
                   5517:                        liberation(s_etat_processus, s_objet_argument);
                   5518:                        liberation(s_etat_processus, s_objet_resultat);
                   5519: 
                   5520:                        (*s_etat_processus).erreur_execution =
                   5521:                                d_ex_erreur_parametre_fichier;
                   5522:                        return;
                   5523:                    }
                   5524:                }
                   5525: 
                   5526:                if (nom != NULL)
                   5527:                {
                   5528:                    /*
                   5529:                     * La socket est dans l'espace des noms.
                   5530:                     */
                   5531: 
                   5532:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   5533:                            .socket = socket(PF_UNIX, type,
                   5534:                            protocole_numerique)) == -1)
                   5535:                    {
                   5536:                        liberation(s_etat_processus, s_objet_argument);
                   5537:                        liberation(s_etat_processus, s_objet_resultat);
                   5538: 
                   5539:                        (*s_etat_processus).erreur_execution =
                   5540:                                d_ex_erreur_acces_fichier;
                   5541:                        return;
                   5542:                    }
                   5543: 
                   5544:                    (*((struct_socket *) (*s_objet_resultat).objet))
                   5545:                            .domaine = PF_UNIX;
                   5546: 
                   5547:                    socket_unix.sun_family = AF_UNIX;
                   5548:                    strncpy(socket_unix.sun_path, (*((struct_socket *)
1.21      bertrand 5549:                            (*s_objet_resultat).objet)).adresse, UNIX_PATH_MAX);
                   5550:                    socket_unix.sun_path[UNIX_PATH_MAX - 1] = d_code_fin_chaine;
1.1       bertrand 5551: 
                   5552:                    if ((type_socket == 'S') || (type_socket == 'Q'))
                   5553:                    {
                   5554:                        if (connect((*((struct_socket *) (*s_objet_resultat)
                   5555:                                .objet)).socket, (const struct sockaddr *)
                   5556:                                &socket_unix, sizeof(socket_unix)) != 0)
                   5557:                        {
                   5558:                            liberation(s_etat_processus, s_objet_argument);
                   5559:                            liberation(s_etat_processus, s_objet_resultat);
                   5560: 
                   5561:                            (*s_etat_processus).erreur_execution =
                   5562:                                    d_ex_erreur_acces_fichier;
                   5563:                            return;
                   5564:                        }
                   5565: 
                   5566:                        (*((struct_socket *) (*s_objet_resultat).objet))
                   5567:                                .socket_connectee = d_vrai;
                   5568:                        (*((struct_socket *) (*s_objet_resultat).objet))
                   5569:                                .socket_en_ecoute = 'N';
                   5570:                    }
                   5571:                }
                   5572:                else
                   5573:                {
                   5574:                    /*
                   5575:                     * La socket est une socket réseau. L'adresse
                   5576:                     * passée en argument est l'adresse sur laquelle
                   5577:                     * cette socket est à l'écoute.
                   5578:                     */
                   5579: 
                   5580:                    if (hote != NULL)
                   5581:                    { // Hôte défini par un nom
                   5582:                        resolution = NULL;
                   5583: 
                   5584:                        if (getaddrinfo(hote, NULL, NULL, &resolution) != 0) 
                   5585:                        {
                   5586:                            liberation(s_etat_processus, s_objet_argument);
                   5587:                            liberation(s_etat_processus, s_objet_resultat);
                   5588: 
                   5589:                            if (resolution != NULL)
                   5590:                            {
                   5591:                                freeaddrinfo(resolution);
                   5592:                            }
                   5593: 
                   5594:                            (*s_etat_processus).erreur_execution =
                   5595:                                    d_ex_erreur_acces_fichier;
                   5596:                            return;
                   5597:                        }
                   5598: 
                   5599:                        if (strcmp(protocole, "IPV4") == 0)
                   5600:                        { // Accès en IPv4
                   5601:                            resolution_courante = resolution;
                   5602: 
                   5603:                            while(resolution_courante != NULL)
                   5604:                            {
                   5605:                                if ((*resolution_courante).ai_family ==
                   5606:                                        AF_INET)
                   5607:                                {
                   5608:                                    break;
                   5609:                                }
                   5610: 
                   5611:                                resolution_courante = (*resolution_courante)
                   5612:                                        .ai_next;
                   5613:                            }
                   5614: 
                   5615:                            if (resolution_courante == NULL)
                   5616:                            {
                   5617:                                liberation(s_etat_processus, s_objet_argument);
                   5618:                                liberation(s_etat_processus, s_objet_resultat);
                   5619: 
                   5620:                                freeaddrinfo(resolution);
                   5621: 
                   5622:                                (*s_etat_processus).erreur_execution =
                   5623:                                        d_ex_erreur_acces_fichier;
                   5624:                                return;
                   5625:                            }
                   5626: 
                   5627:                            if (((*((struct_socket *)
                   5628:                                    (*s_objet_resultat).objet))
                   5629:                                    .socket = socket(PF_INET, type,
                   5630:                                    protocole_numerique)) == -1)
                   5631:                            {
                   5632:                                liberation(s_etat_processus, s_objet_argument);
                   5633:                                liberation(s_etat_processus, s_objet_resultat);
                   5634: 
                   5635:                                freeaddrinfo(resolution);
                   5636: 
                   5637:                                (*s_etat_processus).erreur_execution =
                   5638:                                        d_ex_erreur_acces_fichier;
                   5639:                                return;
                   5640:                            }
                   5641: 
                   5642:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5643:                                .domaine = PF_INET;
                   5644: 
                   5645:                            memset(&socket_ipv4, 0, sizeof(socket_ipv4));
                   5646:                            socket_ipv4.sin_family = AF_INET;
                   5647:                            socket_ipv4.sin_port = htons((uint16_t) port);
                   5648:                            socket_ipv4.sin_addr.s_addr =
                   5649:                                    (*((struct sockaddr_in *)
                   5650:                                    (*resolution_courante).ai_addr))
                   5651:                                    .sin_addr.s_addr;
                   5652: 
                   5653:                            if ((type_socket == 'S') || (type_socket == 'Q'))
                   5654:                            {
                   5655:                                if (connect((*((struct_socket *)
                   5656:                                        (*s_objet_resultat).objet)).socket,
                   5657:                                        (const struct sockaddr *)
                   5658:                                        &socket_ipv4, sizeof(socket_ipv4)) != 0)
                   5659:                                {
                   5660:                                    liberation(s_etat_processus,
                   5661:                                            s_objet_argument);
                   5662:                                    liberation(s_etat_processus,
                   5663:                                            s_objet_resultat);
                   5664: 
                   5665:                                    freeaddrinfo(resolution);
                   5666: 
                   5667:                                    (*s_etat_processus).erreur_execution =
                   5668:                                            d_ex_erreur_acces_fichier;
                   5669:                                    return;
                   5670:                                }
                   5671: 
                   5672:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5673:                                        .socket_connectee = d_vrai;
                   5674:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5675:                                        .socket_en_ecoute = 'N';
                   5676:                            }
                   5677: 
1.51      bertrand 5678:                            free((*((struct_socket *) (*s_objet_resultat)
                   5679:                                    .objet)).adresse);
                   5680: 
1.1       bertrand 5681:                            if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5682:                                    .objet)).adresse = malloc(23 *
1.1       bertrand 5683:                                    sizeof(unsigned char))) == NULL)
                   5684:                            {
                   5685:                                (*s_etat_processus).erreur_systeme =
                   5686:                                        d_es_allocation_memoire;
                   5687:                                return;
                   5688:                            }
                   5689: 
                   5690:                            sprintf((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5691:                                    .objet)).adresse, "%d.%d.%d.%d(%u)",
1.1       bertrand 5692:                                    (ntohl((*((struct sockaddr_in *)
                   5693:                                    (*resolution_courante).ai_addr)).sin_addr
                   5694:                                    .s_addr) >> 24) & 0xFF,
                   5695:                                    (ntohl((*((struct sockaddr_in *)
                   5696:                                    (*resolution_courante).ai_addr)).sin_addr
                   5697:                                    .s_addr) >> 16) & 0xFF,
                   5698:                                    (ntohl((*((struct sockaddr_in *)
                   5699:                                    (*resolution_courante).ai_addr)).sin_addr
                   5700:                                    .s_addr) >> 8) & 0xFF,
                   5701:                                    ntohl((*((struct sockaddr_in *)
                   5702:                                    (*resolution_courante).ai_addr)).sin_addr
1.94      bertrand 5703:                                    .s_addr) & 0xFF,
                   5704:                                    (unsigned int) port);
1.1       bertrand 5705:                        }
                   5706:                        else
                   5707:                        { // Accès en IPv6
1.17      bertrand 5708: #                          ifdef IPV6
1.1       bertrand 5709:                            resolution_courante = resolution;
                   5710: 
                   5711:                            while(resolution_courante != NULL)
                   5712:                            {
                   5713:                                if ((*resolution_courante).ai_family ==
                   5714:                                        AF_INET6)
                   5715:                                {
                   5716:                                    break;
                   5717:                                }
                   5718: 
                   5719:                                resolution_courante = (*resolution_courante)
                   5720:                                        .ai_next;
                   5721:                            }
                   5722: 
                   5723:                            if (resolution_courante == NULL)
                   5724:                            {
                   5725:                                liberation(s_etat_processus, s_objet_argument);
                   5726:                                liberation(s_etat_processus, s_objet_resultat);
                   5727: 
                   5728:                                freeaddrinfo(resolution);
                   5729: 
                   5730:                                (*s_etat_processus).erreur_execution =
                   5731:                                        d_ex_erreur_acces_fichier;
                   5732:                                return;
                   5733:                            }
                   5734: 
                   5735:                            if (((*((struct_socket *)
                   5736:                                    (*s_objet_resultat).objet))
                   5737:                                    .socket = socket(PF_INET6, type,
                   5738:                                    protocole_numerique)) == -1)
                   5739:                            {
                   5740:                                liberation(s_etat_processus, s_objet_argument);
                   5741:                                liberation(s_etat_processus, s_objet_resultat);
                   5742: 
                   5743:                                freeaddrinfo(resolution);
                   5744: 
                   5745:                                (*s_etat_processus).erreur_execution =
                   5746:                                        d_ex_erreur_acces_fichier;
                   5747:                                return;
                   5748:                            }
                   5749: 
                   5750:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5751:                                    .domaine = PF_INET6;
                   5752: 
                   5753:                            memset(&socket_ipv6, 0, sizeof(socket_ipv6));
                   5754:                            socket_ipv6.sin6_family = AF_INET6;
                   5755:                            socket_ipv6.sin6_port = htons((uint16_t) port);
                   5756: 
                   5757:                            for(i = 0; i < 16;
                   5758:                                    socket_ipv6.sin6_addr.s6_addr[i] =
                   5759:                                    (*((struct sockaddr_in6 *)
                   5760:                                    (*resolution_courante).ai_addr))
                   5761:                                    .sin6_addr.s6_addr[i], i++);
                   5762: 
                   5763:                            if ((type_socket == 'S') || (type_socket == 'Q'))
                   5764:                            {
                   5765:                                if (connect((*((struct_socket *)
                   5766:                                        (*s_objet_resultat).objet)).socket,
                   5767:                                        (const struct sockaddr *)
                   5768:                                        &socket_ipv6, sizeof(socket_ipv6)) != 0)
                   5769:                                {
                   5770:                                    liberation(s_etat_processus,
                   5771:                                            s_objet_argument);
                   5772:                                    liberation(s_etat_processus,
                   5773:                                            s_objet_resultat);
                   5774: 
                   5775:                                    freeaddrinfo(resolution);
                   5776: 
                   5777:                                    (*s_etat_processus).erreur_execution =
                   5778:                                            d_ex_erreur_acces_fichier;
                   5779:                                    return;
                   5780:                                }
                   5781: 
                   5782:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5783:                                        .socket_connectee = d_vrai;
                   5784:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5785:                                        .socket_en_ecoute = 'N';
                   5786:                            }
                   5787: 
1.51      bertrand 5788:                            free((*((struct_socket *) (*s_objet_resultat)
                   5789:                                    .objet)).adresse);
                   5790: 
1.1       bertrand 5791:                            if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5792:                                    .objet)).adresse = malloc(47 *
1.1       bertrand 5793:                                    sizeof(unsigned char))) == NULL)
                   5794:                            {
                   5795:                                (*s_etat_processus).erreur_systeme =
                   5796:                                        d_es_allocation_memoire;
                   5797:                                return;
                   5798:                            }
                   5799: 
1.94      bertrand 5800:                            sprintf((*((struct_socket *) (*s_objet_resultat)
                   5801:                                    .objet)).adresse,
                   5802:                                    "%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
                   5803:                                    "%02X%02X:%02X%02X:%02X%02X:%02X%02X(%u)",
                   5804:                                    (*((struct sockaddr_in6 *)
                   5805:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5806:                                    .s6_addr[0],
                   5807:                                    (*((struct sockaddr_in6 *)
                   5808:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5809:                                    .s6_addr[1],
                   5810:                                    (*((struct sockaddr_in6 *)
                   5811:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5812:                                    .s6_addr[2],
                   5813:                                    (*((struct sockaddr_in6 *)
                   5814:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5815:                                    .s6_addr[3],
                   5816:                                    (*((struct sockaddr_in6 *)
                   5817:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5818:                                    .s6_addr[4],
                   5819:                                    (*((struct sockaddr_in6 *)
                   5820:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5821:                                    .s6_addr[5],
                   5822:                                    (*((struct sockaddr_in6 *)
                   5823:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5824:                                    .s6_addr[6],
                   5825:                                    (*((struct sockaddr_in6 *)
                   5826:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5827:                                    .s6_addr[7],
                   5828:                                    (*((struct sockaddr_in6 *)
                   5829:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5830:                                    .s6_addr[8],
                   5831:                                    (*((struct sockaddr_in6 *)
                   5832:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5833:                                    .s6_addr[9],
                   5834:                                    (*((struct sockaddr_in6 *)
                   5835:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5836:                                    .s6_addr[10],
                   5837:                                    (*((struct sockaddr_in6 *)
                   5838:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5839:                                    .s6_addr[11],
                   5840:                                    (*((struct sockaddr_in6 *)
                   5841:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5842:                                    .s6_addr[12],
                   5843:                                    (*((struct sockaddr_in6 *)
                   5844:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5845:                                    .s6_addr[13],
                   5846:                                    (*((struct sockaddr_in6 *)
                   5847:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5848:                                    .s6_addr[14],
                   5849:                                    (*((struct sockaddr_in6 *)
                   5850:                                    (*resolution_courante).ai_addr)).sin6_addr
                   5851:                                    .s6_addr[15],
                   5852:                                    (unsigned int) port);
1.17      bertrand 5853: #                          else
1.19      bertrand 5854:                            if ((*s_etat_processus).langue == 'F')
                   5855:                            {
                   5856:                                printf("+++Attention : Support du protocole"
1.20      bertrand 5857:                                        " IPv6 indisponible\n");
1.19      bertrand 5858:                            }
                   5859:                            else
                   5860:                            {
1.22      bertrand 5861:                                printf("+++Warning : IPv6 support "
1.19      bertrand 5862:                                        "unavailable\n");
                   5863:                            }
1.51      bertrand 5864: 
                   5865:                            liberation(s_etat_processus, s_objet_argument);
                   5866:                            liberation(s_etat_processus, s_objet_resultat);
                   5867: 
                   5868:                            freeaddrinfo(resolution);
                   5869: 
                   5870:                            (*s_etat_processus).erreur_execution =
                   5871:                                    d_ex_instruction_indisponible;
                   5872:                            return;
1.17      bertrand 5873: #                          endif
1.1       bertrand 5874:                        }
                   5875: 
                   5876:                        freeaddrinfo(resolution);
                   5877:                    }
                   5878:                    else
                   5879:                    { // Hôte défini par une adresse
                   5880:                        if (strcmp(protocole, "IPV4") == 0)
                   5881:                        { // Accès en IPv4
                   5882:                            if (type_adresse == '4')
                   5883:                            {
1.51      bertrand 5884:                                free((*((struct_socket *) (*s_objet_resultat)
                   5885:                                        .objet)).adresse);
                   5886: 
1.1       bertrand 5887:                                if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5888:                                        .objet)).adresse = malloc(23 *
1.1       bertrand 5889:                                        sizeof(unsigned char))) == NULL)
                   5890:                                {
                   5891:                                    (*s_etat_processus).erreur_systeme =
                   5892:                                            d_es_allocation_memoire;
                   5893:                                    return;
                   5894:                                }
                   5895: 
                   5896:                                sprintf((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5897:                                        .objet)).adresse, "%d.%d.%d.%d(%u)",
                   5898:                                        (int) adresse[0], (int) adresse[1],
                   5899:                                        (int) adresse[2], (int) adresse[3],
                   5900:                                        (unsigned int) port);
1.1       bertrand 5901:                            }
                   5902:                            else
                   5903:                            {
1.51      bertrand 5904:                                free((*((struct_socket *) (*s_objet_resultat)
                   5905:                                        .objet)).adresse);
                   5906: 
1.1       bertrand 5907:                                if (((*((struct_socket *) (*s_objet_resultat)
                   5908:                                        .objet)).adresse = malloc(
                   5909:                                        sizeof(unsigned char))) == NULL)
                   5910:                                {
                   5911:                                    (*s_etat_processus).erreur_systeme =
                   5912:                                            d_es_allocation_memoire;
                   5913:                                    return;
                   5914:                                }
                   5915: 
                   5916:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5917:                                        .adresse[0] = d_code_fin_chaine;
                   5918:                            }
                   5919: 
                   5920:                            if (((*((struct_socket *)
                   5921:                                    (*s_objet_resultat).objet))
                   5922:                                    .socket = socket(PF_INET, type,
                   5923:                                    protocole_numerique)) == -1)
                   5924:                            {
                   5925:                                liberation(s_etat_processus, s_objet_argument);
                   5926:                                liberation(s_etat_processus, s_objet_resultat);
                   5927: 
                   5928:                                (*s_etat_processus).erreur_execution =
                   5929:                                        d_ex_erreur_acces_fichier;
                   5930:                                return;
                   5931:                            }
                   5932: 
                   5933:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   5934:                                    .domaine = PF_INET;
                   5935: 
                   5936:                            memset(&socket_ipv4, 0, sizeof(socket_ipv4));
                   5937:                            socket_ipv4.sin_family = AF_INET;
                   5938:                            socket_ipv4.sin_port = htons((uint16_t) port);
                   5939: 
                   5940:                            adresse_ipv4 = 0;
                   5941:                            for(i = 0; i < 4; adresse_ipv4 =
1.66      bertrand 5942:                                    (256 * adresse_ipv4)
                   5943:                                    + ((unsigned char) adresse[i++]));
1.1       bertrand 5944: 
                   5945:                            socket_ipv4.sin_addr.s_addr = htonl(adresse_ipv4);
                   5946: 
                   5947:                            if ((type_socket == 'S') || (type_socket == 'Q'))
                   5948:                            {
                   5949:                                if (connect((*((struct_socket *)
                   5950:                                        (*s_objet_resultat).objet)).socket,
                   5951:                                        (const struct sockaddr *)
                   5952:                                        &socket_ipv4, sizeof(socket_ipv4)) != 0)
                   5953:                                {
                   5954:                                    liberation(s_etat_processus,
                   5955:                                            s_objet_argument);
                   5956:                                    liberation(s_etat_processus,
                   5957:                                            s_objet_resultat);
                   5958: 
                   5959:                                    (*s_etat_processus).erreur_execution =
                   5960:                                            d_ex_erreur_acces_fichier;
                   5961:                                    return;
                   5962:                                }
                   5963: 
                   5964:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5965:                                        .socket_connectee = d_vrai;
                   5966:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   5967:                                        .socket_en_ecoute = 'N';
                   5968:                            }
                   5969:                        }
                   5970:                        else if (strcmp(protocole, "IPV6") == 0)
                   5971:                        { // Accès en IPv6
1.17      bertrand 5972: #                          ifdef IPV6
1.1       bertrand 5973:                            if (type_adresse == '6')
                   5974:                            {
1.51      bertrand 5975:                                free((*((struct_socket *) (*s_objet_resultat)
                   5976:                                        .objet)).adresse);
                   5977: 
1.1       bertrand 5978:                                if (((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5979:                                        .objet)).adresse = malloc(47 *
1.1       bertrand 5980:                                        sizeof(unsigned char))) == NULL)
                   5981:                                {
                   5982:                                    (*s_etat_processus).erreur_systeme =
                   5983:                                            d_es_allocation_memoire;
                   5984:                                    return;
                   5985:                                }
                   5986: 
                   5987:                                sprintf((*((struct_socket *) (*s_objet_resultat)
1.94      bertrand 5988:                                        .objet)).adresse,
                   5989:                                        "%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
                   5990:                                        "%02X%02X:%02X%02X:%02X%02X:%02X%02X"
                   5991:                                        "(%u)",
                   5992:                                        (unsigned int) adresse[0],
                   5993:                                        (unsigned int) adresse[1],
                   5994:                                        (unsigned int) adresse[2],
                   5995:                                        (unsigned int) adresse[3],
                   5996:                                        (unsigned int) adresse[4],
                   5997:                                        (unsigned int) adresse[5],
                   5998:                                        (unsigned int) adresse[6],
                   5999:                                        (unsigned int) adresse[7],
                   6000:                                        (unsigned int) adresse[8],
                   6001:                                        (unsigned int) adresse[9],
                   6002:                                        (unsigned int) adresse[10],
                   6003:                                        (unsigned int) adresse[11],
                   6004:                                        (unsigned int) adresse[12],
                   6005:                                        (unsigned int) adresse[13],
                   6006:                                        (unsigned int) adresse[14],
                   6007:                                        (unsigned int) adresse[15],
                   6008:                                        (unsigned int) port);
1.1       bertrand 6009:                            }
                   6010:                            else
                   6011:                            {
1.51      bertrand 6012:                                free((*((struct_socket *) (*s_objet_resultat)
                   6013:                                        .objet)).adresse);
                   6014: 
1.1       bertrand 6015:                                if (((*((struct_socket *) (*s_objet_resultat)
                   6016:                                        .objet)).adresse = malloc(
                   6017:                                        sizeof(unsigned char))) == NULL)
                   6018:                                {
                   6019:                                    (*s_etat_processus).erreur_systeme =
                   6020:                                            d_es_allocation_memoire;
                   6021:                                    return;
                   6022:                                }
                   6023: 
                   6024:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   6025:                                        .adresse[0] = d_code_fin_chaine;
                   6026:                            }
                   6027: 
                   6028:                            if (((*((struct_socket *)
                   6029:                                    (*s_objet_resultat).objet))
                   6030:                                    .socket = socket(PF_INET6, type,
                   6031:                                    protocole_numerique)) == -1)
                   6032:                            {
                   6033:                                liberation(s_etat_processus, s_objet_argument);
                   6034:                                liberation(s_etat_processus, s_objet_resultat);
                   6035: 
                   6036:                                (*s_etat_processus).erreur_execution =
                   6037:                                        d_ex_erreur_acces_fichier;
                   6038:                                return;
                   6039:                            }
                   6040: 
                   6041:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   6042:                                    .domaine = PF_INET6;
                   6043: 
                   6044:                            memset(&socket_ipv6, 0, sizeof(socket_ipv6));
                   6045:                            socket_ipv6.sin6_family = AF_INET6;
                   6046:                            socket_ipv6.sin6_port = htons((uint16_t) port);
                   6047: 
                   6048:                            for(i = 0; i < 16;
                   6049:                                    socket_ipv6.sin6_addr.s6_addr[i] =
                   6050:                                    (unsigned char) (adresse[i]), i++);
                   6051: 
                   6052:                            if ((type_socket == 'S') || (type_socket == 'Q'))
                   6053:                            {
                   6054:                                if (connect((*((struct_socket *)
                   6055:                                        (*s_objet_resultat).objet)).socket,
                   6056:                                        (const struct sockaddr *)
                   6057:                                        &socket_ipv6, sizeof(socket_ipv6)) != 0)
                   6058:                                {
                   6059:                                    liberation(s_etat_processus,
                   6060:                                            s_objet_argument);
                   6061:                                    liberation(s_etat_processus,
                   6062:                                            s_objet_resultat);
                   6063: 
                   6064:                                    (*s_etat_processus).erreur_execution =
                   6065:                                            d_ex_erreur_acces_fichier;
                   6066:                                    return;
                   6067:                                }
                   6068: 
                   6069:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   6070:                                        .socket_connectee = d_vrai;
                   6071:                                (*((struct_socket *) (*s_objet_resultat).objet))
                   6072:                                        .socket_en_ecoute = 'N';
                   6073:                            }
1.17      bertrand 6074: #                          else
1.19      bertrand 6075:                            if ((*s_etat_processus).langue == 'F')
                   6076:                            {
                   6077:                                printf("+++Attention : Support du protocole"
1.20      bertrand 6078:                                        " IPv6 indisponible\n");
1.19      bertrand 6079:                            }
                   6080:                            else
                   6081:                            {
1.22      bertrand 6082:                                printf("+++Warning : IPv6 support "
1.19      bertrand 6083:                                        "unavailable\n");
                   6084:                            }
1.51      bertrand 6085: 
                   6086:                            liberation(s_etat_processus, s_objet_argument);
                   6087:                            liberation(s_etat_processus, s_objet_resultat);
                   6088: 
                   6089:                            (*s_etat_processus).erreur_execution =
                   6090:                                    d_ex_instruction_indisponible;
                   6091:                            return;
1.17      bertrand 6092: #                          endif
1.1       bertrand 6093:                        }
                   6094:                        else
                   6095:                        { // Socket UNIX
1.51      bertrand 6096:                            free((*((struct_socket *) (*s_objet_resultat)
                   6097:                                    .objet)).adresse);
                   6098: 
1.1       bertrand 6099:                            if (((*((struct_socket *) (*s_objet_resultat)
                   6100:                                    .objet)).adresse = malloc(
                   6101:                                    sizeof(unsigned char))) == NULL)
                   6102:                            {
                   6103:                                (*s_etat_processus).erreur_systeme =
                   6104:                                        d_es_allocation_memoire;
                   6105:                                return;
                   6106:                            }
                   6107: 
                   6108:                            (*((struct_socket *) (*s_objet_resultat).objet))
                   6109:                                    .adresse[0] = d_code_fin_chaine;
                   6110: 
                   6111:                            if (((*((struct_socket *)
                   6112:                                    (*s_objet_resultat).objet))
                   6113:                                    .socket = socket(PF_UNIX, type,
                   6114:                                    protocole_numerique)) == -1)
                   6115:                            {
                   6116:                                liberation(s_etat_processus, s_objet_argument);
                   6117:                                liberation(s_etat_processus, s_objet_resultat);
                   6118: 
                   6119:                                (*s_etat_processus).erreur_execution =
                   6120:                                        d_ex_erreur_acces_fichier;
                   6121:                                return;
                   6122:                            }
                   6123:                        }
                   6124:                    }
                   6125: 
                   6126:                    (*((struct_socket *) (*s_objet_resultat).objet)).effacement
                   6127:                            = 'N';
                   6128:                }
                   6129: 
                   6130:                if ((type_socket == 'S') || (type_socket == 'Q'))
                   6131:                {
                   6132:                    if (protection == 'R')
                   6133:                    { // WRITEONLY
                   6134:                        if (shutdown((*((struct_socket *) (*s_objet_resultat)
                   6135:                                .objet)).socket, SHUT_RD) != 0)
                   6136:                        {
                   6137:                            liberation(s_etat_processus, s_objet_argument);
                   6138:                            liberation(s_etat_processus, s_objet_resultat);
                   6139: 
                   6140:                            (*s_etat_processus).erreur_execution =
                   6141:                                    d_ex_erreur_acces_fichier;
                   6142:                            return;
                   6143:                        }
                   6144:                    }
                   6145:                    else if (protection == 'W')
                   6146:                    { // READONLY
                   6147:                        if (shutdown((*((struct_socket *) (*s_objet_resultat)
                   6148:                                .objet)).socket, SHUT_WR) != 0)
                   6149:                        {
                   6150:                            liberation(s_etat_processus, s_objet_argument);
                   6151:                            liberation(s_etat_processus, s_objet_resultat);
                   6152: 
                   6153:                            (*s_etat_processus).erreur_execution =
                   6154:                                    d_ex_erreur_acces_fichier;
                   6155:                            return;
                   6156:                        }
                   6157:                    }
                   6158:                    else
                   6159:                    { // READWRITE
                   6160:                    }
                   6161:                }
                   6162:            }
                   6163: 
                   6164:            /*
                   6165:             * Gestion de la liste des sockets ouvertes
                   6166:             */
                   6167: 
                   6168:            l_element_courant = (*s_etat_processus).s_sockets;
                   6169: 
                   6170:            if (l_element_courant == NULL)
                   6171:            {
                   6172:                if (((*s_etat_processus).s_sockets =
                   6173:                        allocation_maillon(s_etat_processus)) == NULL)
                   6174:                {
                   6175:                    (*s_etat_processus).erreur_systeme =
                   6176:                            d_es_allocation_memoire;
                   6177:                    return;
                   6178:                }
                   6179: 
                   6180:                (*(*s_etat_processus).s_sockets).suivant = NULL;
                   6181:                l_element_courant = (*s_etat_processus).s_sockets;
                   6182:            }
                   6183:            else
                   6184:            {
                   6185:                /*
                   6186:                 * Ajout d'un élément à la fin de la liste chaînée
                   6187:                 */
                   6188: 
                   6189:                while((*l_element_courant).suivant != NULL)
                   6190:                {
                   6191:                    l_element_courant = (*l_element_courant).suivant;
                   6192:                }
                   6193: 
                   6194:                if (((*l_element_courant).suivant =
                   6195:                        allocation_maillon(s_etat_processus)) == NULL)
                   6196:                {
                   6197:                    (*s_etat_processus).erreur_systeme =
                   6198:                            d_es_allocation_memoire;
                   6199:                    return;
                   6200:                }
                   6201: 
                   6202:                l_element_courant = (*l_element_courant).suivant;
                   6203:                (*l_element_courant).suivant = NULL;
                   6204:            }
                   6205: 
                   6206:            if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
                   6207:                    s_objet_resultat, 'O')) == NULL)
                   6208:            {
                   6209:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   6210:                return;
                   6211:            }
1.13      bertrand 6212: 
                   6213:            liberation(s_etat_processus, s_objet_argument);
1.1       bertrand 6214:        }
                   6215:        else
                   6216:        {
                   6217:            liberation(s_etat_processus, s_objet_argument);
                   6218: 
                   6219:            (*s_etat_processus).erreur_execution =
                   6220:                    d_ex_erreur_parametre_fichier;
                   6221:            return;
                   6222:        }
                   6223:    }
                   6224:    else if ((*s_objet_argument).type == CHN)
                   6225:    {
                   6226:        if ((s_objet_resultat = allocation(s_etat_processus, SPH)) == NULL)
                   6227:        {
                   6228:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   6229:            return;
                   6230:        }
                   6231: 
                   6232:        if (((*((struct_semaphore *) (*s_objet_resultat).objet)).nom =
                   6233:                malloc((strlen((unsigned char *) (*s_objet_argument).objet)
                   6234:                + 1) *sizeof(unsigned char))) == NULL)
                   6235:        {
                   6236:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   6237:            return;
                   6238:        }
                   6239: 
                   6240:        strcpy((*((struct_semaphore *) (*s_objet_resultat).objet)).nom,
                   6241:                (unsigned char *) (*s_objet_argument).objet);
                   6242: 
                   6243:        if (((*((struct_semaphore *) (*s_objet_resultat).objet)).semaphore =
                   6244:                sem_open((*((struct_semaphore *) (*s_objet_resultat).objet))
                   6245:                .nom, 0)) == SEM_FAILED)
                   6246:        {
                   6247:            if (errno == ENOMEM)
                   6248:            {
                   6249:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   6250:                return;
                   6251:            }
                   6252: 
                   6253:            (*s_etat_processus).erreur_execution = d_ex_semaphore;
                   6254: 
                   6255:            liberation(s_etat_processus, s_objet_argument);
                   6256:            liberation(s_etat_processus, s_objet_resultat);
                   6257:            return;
                   6258:        }
                   6259:    }
                   6260:    else
                   6261:    {
                   6262:        liberation(s_etat_processus, s_objet_argument);
                   6263: 
                   6264:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   6265:        return;
                   6266:    }
                   6267: 
                   6268:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   6269:            s_objet_resultat) == d_erreur)
                   6270:    {
                   6271:        return;
                   6272:    }
                   6273: 
                   6274:    return;
                   6275: }
                   6276: 
                   6277: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>