Diff for /rpl/src/instructions_o1.c between versions 1.44 and 1.47

version 1.44, 2012/01/17 14:44:08 version 1.47, 2012/02/23 15:53:27
Line 926  instruction_open(struct_processus *s_eta Line 926  instruction_open(struct_processus *s_eta
   
     struct_liste_chainee        *l_element_courant;      struct_liste_chainee        *l_element_courant;
     struct_liste_chainee        *l_element_courant_sous_objet;      struct_liste_chainee        *l_element_courant_sous_objet;
       struct_liste_chainee        *parametre_courant;
   
     struct flock                lock;      struct flock                lock;
   
Line 942  instruction_open(struct_processus *s_eta Line 943  instruction_open(struct_processus *s_eta
   
     struct_objet                *s_objet_argument;      struct_objet                *s_objet_argument;
     struct_objet                *s_objet_resultat;      struct_objet                *s_objet_resultat;
       struct_objet                *s_parametres_tty;
   
       struct termios              tc;
   
     uint32_t                    adresse_ipv4;      uint32_t                    adresse_ipv4;
   
Line 952  instruction_open(struct_processus *s_eta Line 956  instruction_open(struct_processus *s_eta
     unsigned char               *nom;      unsigned char               *nom;
     unsigned char               *nom_temporaire;      unsigned char               *nom_temporaire;
     unsigned char               options[12];      unsigned char               options[12];
       unsigned char               *parametre_courant_majuscule;
     unsigned char               *peripherique;      unsigned char               *peripherique;
     unsigned char               *pointeur;      unsigned char               *pointeur;
       unsigned char               *position;
     unsigned char               protection;      unsigned char               protection;
     unsigned char               protocole[16 + 1];      unsigned char               protocole[16 + 1];
     unsigned char               *protocole_socket;      unsigned char               *protocole_socket;
Line 1019  instruction_open(struct_processus *s_eta Line 1025  instruction_open(struct_processus *s_eta
   
         printf("    { \"filetype\" \"access\" \"format\" { \"name\" "          printf("    { \"filetype\" \"access\" \"format\" { \"name\" "
                 "\"file name\" } \"protection\" } OPEN\n");                  "\"file name\" } \"protection\" } OPEN\n");
           printf("    { \"filetype\" \"access\" \"format\" { \"name\" "
                   "\"file name\" } \n"
                   "           { \"stty\" { \"stty parameters\" ... } } } OPEN\n");
         printf("    { \"sockettype\" { \"name\" \"local name\" } } OPEN\n");          printf("    { \"sockettype\" { \"name\" \"local name\" } } OPEN\n");
         printf("    { \"sockettype\" \"socketdomain\" \"protection\" } OPEN\n");          printf("    { \"sockettype\" \"socketdomain\" \"protection\" } OPEN\n");
         printf("    \"/semaphore\" OPEN\n");          printf("    \"/semaphore\" OPEN\n");
Line 1031  instruction_open(struct_processus *s_eta Line 1040  instruction_open(struct_processus *s_eta
         printf("    Socket protocol : IPV4/IPV6/UNIX\n");          printf("    Socket protocol : IPV4/IPV6/UNIX\n");
         printf("    Format          : FORMATTED/UNFORMATTED/FLOW\n");          printf("    Format          : FORMATTED/UNFORMATTED/FLOW\n");
         printf("    Protection      : READONLY/WRITEONLY/READWRITE\n\n");          printf("    Protection      : READONLY/WRITEONLY/READWRITE\n\n");
           printf("    Stty parameters : can be prefixed by 'NO'\n");
           printf("            IGNBRK, BRKINT, IGNPAR, PARMRK, INPCK, ISTRIP\n");
           printf("            INLCR, IGNCR, ICRNL, IXON, IXANY, IXOFF,\n");
           printf("            IMAXBEL, OPOST, ONLCR, OCRNL, ONOCR, ONLRET,\n");
           printf("            OFILL, HUPCL, CLOCAL, CRTSCTS, ISIG, ICANON,\n");
           printf("            ECHO, ECHOE, ECHOK, ECHONL, NOFLSH, TOSTOP,\n");
           printf("            IEXTEN, VEOF, VEOL, VERASE, VINTR, VKILL,\n");
           printf("            VQUIT, VSTART, VSTOP, VSUSP\n");
   
         printf("    Address         : { \"ADDRESS\" [ 127 0 0 1 ] }\n");          printf("    Address         : { \"ADDRESS\" [ 127 0 0 1 ] }\n");
         printf("                      { \"HOST\" \"hostname\" }\n");          printf("                      { \"HOST\" \"hostname\" }\n");
Line 1061  instruction_open(struct_processus *s_eta Line 1078  instruction_open(struct_processus *s_eta
         printf("    { \"STREAM\" \"READWRITE\" } OPEN\n");          printf("    { \"STREAM\" \"READWRITE\" } OPEN\n");
         printf("    { \"FOREIGN\" \"DATAGRAM\" } OPEN\n");          printf("    { \"FOREIGN\" \"DATAGRAM\" } OPEN\n");
         printf("    { \"LOCAL\" { \"NAME\" \"socket.sock\" } } OPEN\n");          printf("    { \"LOCAL\" { \"NAME\" \"socket.sock\" } } OPEN\n");
           printf("    { \"/dev/ttyS1\" { \"STTY\" { \"9600,8,N,1\" "
                   "\"NO ICANON\" \"IGNBRK\" } }\n");
   
         return;          return;
     }      }
Line 1121  instruction_open(struct_processus *s_eta Line 1140  instruction_open(struct_processus *s_eta
         timeout_emission = 0;          timeout_emission = 0;
         timeout_reception = 0;          timeout_reception = 0;
         drapeau = -1;          drapeau = -1;
           s_parametres_tty = NULL;
   
         for(i = 0; i < 12; options[i++] = 'N');          for(i = 0; i < 12; options[i++] = 'N');
   
Line 1973  instruction_open(struct_processus *s_eta Line 1993  instruction_open(struct_processus *s_eta
                                         (*(*l_element_courant_sous_objet)                                          (*(*l_element_courant_sous_objet)
                                         .donnee).objet;                                          .donnee).objet;
   
                 for(i = 0; i < strlen(protocole_socket); i++)                                  for(i = 0; i < strlen(protocole_socket); i++)
                 {                                  {
                     if ((protocole_socket[i] >= 'a') &&                                      if ((protocole_socket[i] >= 'a') &&
                             (protocole_socket[i] <= 'z'))                                              (protocole_socket[i] <= 'z'))
                     {                                      {
                         protocole_socket[i] -= 'a' - 'A';                                          protocole_socket[i] -= 'a' - 'A';
                     }                                      }
                 }                                  }
   
                             }                              }
                             else                              else
                             {                              {
Line 2250  instruction_open(struct_processus *s_eta Line 2269  instruction_open(struct_processus *s_eta
                                 }                                  }
                             }                              }
                         }                          }
                           else if (strcmp(argument_majuscule, "STTY") == 0)
                           {
                               if ((*(*l_element_courant_sous_objet)
                                       .donnee).type == LST)
                               {
                                   if (type_arguments == ' ')
                                   {
                                       type_arguments = 'F';
                                   }
                                   else if (type_arguments == 'S')
                                   {
                                       liberation(s_etat_processus,
                                               s_objet_argument);
                                       free(argument_majuscule);
   
                                       (*s_etat_processus).erreur_execution =
                                               d_ex_erreur_parametre_fichier;
                                       return;
                                   }
   
                                   s_parametres_tty =
                                           (*l_element_courant_sous_objet).donnee;
                               }
                           }
                         else                          else
                         {                          {
                             liberation(s_etat_processus, s_objet_argument);                              liberation(s_etat_processus, s_objet_argument);
Line 3480  instruction_open(struct_processus *s_eta Line 3523  instruction_open(struct_processus *s_eta
                 return;                  return;
             }              }
   
               if (s_parametres_tty != NULL)
               {
                   // Affectation des paramètres du port série.
   
                   if (tcgetattr(fileno(descripteur), &tc) != 0)
                   {
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_systeme =
                               d_ex_erreur_fichier;
                       return;
                   }
   
                   parametre_courant = (*s_parametres_tty).objet;
   
                   // Le premier paramètre concerne la vitesse du port. Il doit
                   // toujours être présent.
   
                   if (parametre_courant == NULL)
                   {
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_execution =
                               d_ex_erreur_parametre_fichier;
                       return;
                   }
   
                   if ((*(*parametre_courant).donnee).type != CHN)
                   {
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_execution =
                               d_ex_erreur_parametre_fichier;
                       return;
                   }
   
                   if ((parametre_courant_majuscule = conversion_majuscule(
                           (*(*parametre_courant).donnee).objet)) == NULL)
                   {
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_systeme =
                               d_es_allocation_memoire;
                       return;
                   }
   
                   position = parametre_courant_majuscule;
   
                   while((*position) != d_code_fin_chaine)
                   {
                       if ((*position) == ',')
                       {
                           (*position) = ' ';
                       }
   
                       position++;
                   }
   
                   position = parametre_courant_majuscule;
   
                   while((*position) != d_code_fin_chaine)
                   {
                       if (isalnum((*position)) != 0)
                       {
                           break;
                       }
   
                       position++;
                   }
   
                   // Vitesse
   
                   unsigned char   *vitesses[] =
                           { "B0", "B50", "B75", "B110", "B134", "B150",
                           "B200", "B300", "B600", "B1200", "B1800", "B2400",
                           "B4800", "B9600", "B19200", "B38400", "B57600",
                           "B115200", "B230400", NULL };
                   int             vitesses_constantes[] =
                           { B0, B50, B75, B110, B134, B150, B200, B300, B600,
                           B1200, B1800, B2400, B4800, B9600, B19200, B38400,
                           B57600, B115200, B230400, 0 };
                   unsigned int    vitesse_courante;
   
                   vitesse_courante = 0;
   
                   while(vitesses[vitesse_courante] != NULL)
                   {
                       if (strncmp(position, vitesses[vitesse_courante],
                               strlen(vitesses[vitesse_courante])) == 0)
                       {
                           if (position[strlen(vitesses[vitesse_courante])] ==
                                   d_code_espace)
                           {
                               tc.c_cflag &= ~CBAUD;
                               tc.c_cflag |= vitesses_constantes[vitesse_courante];
                               position += strlen(vitesses[vitesse_courante]);
   
                               break;
                           }
                       }
   
                       vitesse_courante++;
                   }
   
                   if (vitesses[vitesse_courante] == NULL)
                   {
                       // La vitesse indiquée n'est pas une vitesse autorisée.
   
                       free(parametre_courant_majuscule);
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_execution =
                               d_ex_erreur_parametre_fichier;
                       return;
                   }
   
                   // Nombre de bits par caractère.
   
                   while((*position) != d_code_fin_chaine)
                   {
                       if (isalnum((*position)) != 0)
                       {
                           break;
                       }
   
                       position++;
                   }
   
                   switch((*position))
                   {
                       case '5':
                       {
                           tc.c_cflag &= ~CSIZE;
                           tc.c_cflag |= CS5;
                           break;
                       }
   
                       case '6':
                       {
                           tc.c_cflag &= ~CSIZE;
                           tc.c_cflag |= CS6;
                           break;
                       }
   
                       case '7':
                       {
                           tc.c_cflag &= ~CSIZE;
                           tc.c_cflag |= CS7;
                           break;
                       }
   
                       case '8':
                       {
                           tc.c_cflag &= ~CSIZE;
                           tc.c_cflag |= CS8;
                           break;
                       }
   
                       default:
                       {
                           free(parametre_courant_majuscule);
                           liberation(s_etat_processus, s_objet_argument);
                           liberation(s_etat_processus, s_objet_resultat);
   
                           (*s_etat_processus).erreur_execution =
                                   d_ex_erreur_parametre_fichier;
                           return;
                       }
                   }
   
                   position++;
   
                   if ((*position) != d_code_espace)
                   {
                       free(parametre_courant_majuscule);
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_execution =
                               d_ex_erreur_parametre_fichier;
                       return;
                   }
   
                   // Parité
   
                   while((*position) != d_code_fin_chaine)
                   {
                       if (isalnum((*position)) != 0)
                       {
                           break;
                       }
   
                       position++;
                   }
   
                   switch((*position))
                   {
                       case 'N':
                       {
                           tc.c_cflag &= ~PARENB;
                           break;
                       }
   
                       case 'O':
                       {
                           tc.c_cflag |= PARENB;
                           tc.c_cflag |= PARODD;
                           break;
                       }
   
                       case 'E':
                       {
                           tc.c_cflag |= PARENB;
                           tc.c_cflag &= ~PARODD;
                           break;
                       }
   
                       default:
                       {
                           free(parametre_courant_majuscule);
                           liberation(s_etat_processus, s_objet_argument);
                           liberation(s_etat_processus, s_objet_resultat);
   
                           (*s_etat_processus).erreur_execution =
                                   d_ex_erreur_parametre_fichier;
                           return;
                       }
                   }
   
                   if ((*position) != d_code_espace)
                   {
                       free(parametre_courant_majuscule);
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_execution =
                               d_ex_erreur_parametre_fichier;
                       return;
                   }
   
                   // Bits de stop
   
                   while((*position) != d_code_fin_chaine)
                   {
                       if (isalnum((*position)) != 0)
                       {
                           break;
                       }
   
                       position++;
                   }
   
                   switch((*position))
                   {
                       case '1':
                       {
                           tc.c_cflag &= ~CSTOPB;
                           break;
                       }
   
                       case '2':
                       {
                           tc.c_cflag |= CSTOPB;
                           break;
                       }
   
                       default:
                       {
                           free(parametre_courant_majuscule);
                           liberation(s_etat_processus, s_objet_argument);
                           liberation(s_etat_processus, s_objet_resultat);
   
                           (*s_etat_processus).erreur_execution =
                                   d_ex_erreur_parametre_fichier;
                           return;
                       }
                   }
   
                   // S'il reste autre chose que des espaces, il y a un
                   // problème de paramètres.
   
                   while((*position) != d_code_fin_chaine)
                   {
                       if ((*position) != d_code_espace)
                       {
                           free(parametre_courant_majuscule);
                           liberation(s_etat_processus, s_objet_argument);
                           liberation(s_etat_processus, s_objet_resultat);
   
                           (*s_etat_processus).erreur_execution =
                                   d_ex_erreur_parametre_fichier;
                           return;
                       }
   
                       position++;
                   }
   
                   // Autres paramètres
   
                   free(parametre_courant_majuscule);
   
                   while(parametre_courant != NULL)
                   {
                       parametre_courant = (*parametre_courant).suivant;
                   }
   
                   if (tcsetattr(fileno(descripteur), TCSANOW, &tc) != 0)
                   {
                       liberation(s_etat_processus, s_objet_argument);
                       liberation(s_etat_processus, s_objet_resultat);
   
                       (*s_etat_processus).erreur_systeme =
                               d_ex_erreur_fichier;
                       return;
                   }
               }
   
             strcpy((*((struct_fichier *) (*s_objet_resultat).objet)).nom, nom);              strcpy((*((struct_fichier *) (*s_objet_resultat).objet)).nom, nom);
             liberation(s_etat_processus, s_objet_argument);              liberation(s_etat_processus, s_objet_argument);
   

Removed from v.1.44  
changed lines
  Added in v.1.47


CVSweb interface <joel.bertrand@systella.fr>