![]() ![]() | ![]() |
1.1 bertrand 1: /*
2: ================================================================================
1.86 bertrand 3: RPL/2 (R) version 4.1.17
1.87 ! bertrand 4: Copyright (C) 1989-2014 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.19 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
28: Fonction 'r->b'
29: ================================================================================
30: Entrées : pointeur sur une structure struct_processus
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_r_vers_b(struct_processus *s_etat_processus)
40: {
41: struct_objet *s_objet_argument;
42: struct_objet *s_objet_resultat;
43:
44: (*s_etat_processus).erreur_execution = d_ex;
45:
46: if ((*s_etat_processus).affichage_arguments == 'Y')
47: {
48: printf("\n R->B ");
49:
50: if ((*s_etat_processus).langue == 'F')
51: {
52: printf("(réel vers binaire)\n\n");
53: }
54: else
55: {
56: printf("(real to binary)\n\n");
57: }
58:
59: printf(" 1: %s\n", d_INT);
60: printf("-> 1: %s\n", d_BIN);
61:
62: return;
63: }
64: else if ((*s_etat_processus).test_instruction == 'Y')
65: {
66: (*s_etat_processus).nombre_arguments = -1;
67: return;
68: }
69:
70: if (test_cfsf(s_etat_processus, 31) == d_vrai)
71: {
72: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
73: {
74: return;
75: }
76: }
77:
78: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
79: &s_objet_argument) == d_erreur)
80: {
81: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
82: return;
83: }
84:
85: if ((*s_objet_argument).type == INT)
86: {
87: if ((s_objet_resultat = allocation(s_etat_processus, BIN)) == NULL)
88: {
89: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
90: return;
91: }
92:
93: if ((*((integer8 *) (*s_objet_argument).objet)) < 0)
94: {
95: (*((logical8 *) (*s_objet_resultat).objet)) = 0;
96: }
97: else
98: {
1.76 bertrand 99: (*((logical8 *) (*s_objet_resultat).objet)) = (logical8)
100: (*((integer8 *) (*s_objet_argument).objet));
1.1 bertrand 101: }
102: }
103: else
104: {
105: liberation(s_etat_processus, s_objet_argument);
106:
107: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
108: return;
109: }
110:
111: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
112: s_objet_resultat) == d_erreur)
113: {
114: return;
115: }
116:
117: liberation(s_etat_processus, s_objet_argument);
118: return;
119: }
120:
121:
122: /*
123: ================================================================================
124: Fonction 'rl'
125: ================================================================================
126: Entrées : pointeur sur une structure struct_processus
127: --------------------------------------------------------------------------------
128: Sorties :
129: --------------------------------------------------------------------------------
130: Effets de bord : néant
131: ================================================================================
132: */
133:
134: void
135: instruction_rl(struct_processus *s_etat_processus)
136: {
137: logical8 masque;
138: logical8 tampon;
139:
140: struct_objet *s_copie;
141: struct_objet *s_objet;
142:
143: unsigned long i;
144: unsigned long j;
145: unsigned long longueur;
146:
147: (*s_etat_processus).erreur_execution = d_ex;
148:
149: if ((*s_etat_processus).affichage_arguments == 'Y')
150: {
151: printf("\n RL ");
152:
153: if ((*s_etat_processus).langue == 'F')
154: {
155: printf("(rotation à gauche)\n\n");
156: }
157: else
158: {
159: printf("(rotate left)\n\n");
160: }
161:
162: printf(" 1: %s\n", d_BIN);
163: printf("-> 1: %s\n", d_BIN);
164:
165: return;
166: }
167: else if ((*s_etat_processus).test_instruction == 'Y')
168: {
169: (*s_etat_processus).nombre_arguments = -1;
170: return;
171: }
172:
173: if (test_cfsf(s_etat_processus, 31) == d_vrai)
174: {
175: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
176: {
177: return;
178: }
179: }
180:
181: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
182: &s_objet) == d_erreur)
183: {
184: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
185: return;
186: }
187:
188: if ((*s_objet).type == BIN)
189: {
190: if ((s_copie = copie_objet(s_etat_processus, s_objet, 'O')) == NULL)
191: {
192: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
193: return;
194: }
195:
196: longueur = 1;
197: j = 1;
198:
199: for(i = 37; i <= 42; i++)
200: {
201: longueur += (test_cfsf(s_etat_processus, (unsigned char) i)
202: == d_vrai) ? j : 0;
203: j *= 2;
204: }
205:
206: tampon = (*((logical8 *) (*s_copie).objet));
207: masque = ((logical8) 1) << (longueur - 1);
208:
209: if ((tampon & masque) == 0)
210: {
211: tampon <<= 1;
212: }
213: else
214: {
215: tampon <<= 1;
216: tampon |= (logical8) 1;
217: }
218:
219: for(masque = 0, i = 0; i < longueur; i++)
220: {
221: masque <<= 1;
222: masque |= (logical8) 1;
223: }
224:
225: tampon &= masque;
226: (*((logical8 *) (*s_copie).objet)) = tampon;
227:
228: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
229: s_copie) == d_erreur)
230: {
231: return;
232: }
233: }
234: else
235: {
236: liberation(s_etat_processus, s_objet);
237:
238: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
239: return;
240: }
241:
242: liberation(s_etat_processus, s_objet);
243:
244: return;
245: }
246:
247:
248: /*
249: ================================================================================
250: Fonction 'rlb'
251: ================================================================================
252: Entrées : pointeur sur une structure struct_processus
253: --------------------------------------------------------------------------------
254: Sorties :
255: --------------------------------------------------------------------------------
256: Effets de bord : néant
257: ================================================================================
258: */
259:
260: void
261: instruction_rlb(struct_processus *s_etat_processus)
262: {
263: struct_liste_chainee *l_base_pile;
264:
265: unsigned long i;
266:
267: (*s_etat_processus).erreur_execution = d_ex;
268:
269: if ((*s_etat_processus).affichage_arguments == 'Y')
270: {
271: printf("\n RLB ");
272:
273: if ((*s_etat_processus).langue == 'F')
274: {
275: printf("(rotation d'un octet vers la gauche)\n\n");
276: }
277: else
278: {
279: printf("(rotate left byte)\n\n");
280: }
281:
282: printf(" 1: %s\n", d_BIN);
283: printf("-> 1: %s\n", d_BIN);
284:
285: return;
286: }
287: else if ((*s_etat_processus).test_instruction == 'Y')
288: {
289: (*s_etat_processus).nombre_arguments = -1;
290: return;
291: }
292:
293: if (test_cfsf(s_etat_processus, 31) == d_vrai)
294: {
295: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
296: {
297: return;
298: }
299: }
300:
301: l_base_pile = (*s_etat_processus).l_base_pile_last;
302: (*s_etat_processus).l_base_pile_last = NULL;
303:
304: for(i = 0; i < 8; i++)
305: {
306: instruction_rl(s_etat_processus);
307:
308: if (((*s_etat_processus).erreur_systeme != d_es) ||
309: ((*s_etat_processus).erreur_execution != d_ex))
310: {
311: break;
312: }
313: }
314:
315: if (test_cfsf(s_etat_processus, 31) == d_vrai)
316: {
317: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
318: {
319: return;
320: }
321: }
322:
323: (*s_etat_processus).l_base_pile_last = l_base_pile;
324: return;
325: }
326:
327:
328: /*
329: ================================================================================
330: Fonction 'rr'
331: ================================================================================
332: Entrées : pointeur sur une structure struct_processus
333: --------------------------------------------------------------------------------
334: Sorties :
335: --------------------------------------------------------------------------------
336: Effets de bord : néant
337: ================================================================================
338: */
339:
340: void
341: instruction_rr(struct_processus *s_etat_processus)
342: {
343: logical8 masque;
344: logical8 tampon;
345:
346: struct_objet *s_copie;
347: struct_objet *s_objet;
348:
349: unsigned long i;
350: unsigned long j;
351: unsigned long longueur;
352:
353: (*s_etat_processus).erreur_execution = d_ex;
354:
355: if ((*s_etat_processus).affichage_arguments == 'Y')
356: {
357: printf("\n RR ");
358:
359: if ((*s_etat_processus).langue == 'F')
360: {
361: printf("(rotation à droite)\n\n");
362: }
363: else
364: {
365: printf("(rotate right)\n\n");
366: }
367:
368: printf(" 1: %s\n", d_BIN);
369: printf("-> 1: %s\n", d_BIN);
370:
371: return;
372: }
373: else if ((*s_etat_processus).test_instruction == 'Y')
374: {
375: (*s_etat_processus).nombre_arguments = -1;
376: return;
377: }
378:
379: if (test_cfsf(s_etat_processus, 31) == d_vrai)
380: {
381: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
382: {
383: return;
384: }
385: }
386:
387: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
388: &s_objet) == d_erreur)
389: {
390: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
391: return;
392: }
393:
394: if ((*s_objet).type == BIN)
395: {
396: if ((s_copie = copie_objet(s_etat_processus, s_objet, 'O')) == NULL)
397: {
398: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
399: return;
400: }
401:
402: longueur = 1;
403: j = 1;
404:
405: for(i = 37; i <= 42; i++)
406: {
407: longueur += (test_cfsf(s_etat_processus, (unsigned char) i)
408: == d_vrai) ? j : 0;
409: j *= 2;
410: }
411:
412: tampon = (*((logical8 *) (*s_copie).objet));
413: masque = (logical8) 1;
414:
415: if ((tampon & masque) == 0)
416: {
417: tampon >>= 1;
418: }
419: else
420: {
421: tampon >>= 1;
422: tampon |= (((logical8) 1) << (longueur - 1));
423: }
424:
425: for(masque = 0, i = 0; i < longueur; i++)
426: {
427: masque <<= 1;
428: masque |= 1;
429: }
430:
431: tampon &= masque;
432: (*((logical8 *) (*s_copie).objet)) = tampon;
433:
434: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
435: s_copie) == d_erreur)
436: {
437: return;
438: }
439: }
440: else
441: {
442: liberation(s_etat_processus, s_objet);
443:
444: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
445: return;
446: }
447:
448: liberation(s_etat_processus, s_objet);
449:
450: return;
451: }
452:
453:
454: /*
455: ================================================================================
456: Fonction 'rrb'
457: ================================================================================
458: Entrées : pointeur sur une structure struct_processus
459: --------------------------------------------------------------------------------
460: Sorties :
461: --------------------------------------------------------------------------------
462: Effets de bord : néant
463: ================================================================================
464: */
465:
466: void
467: instruction_rrb(struct_processus *s_etat_processus)
468: {
469: struct_liste_chainee *l_base_pile;
470:
471: unsigned long i;
472:
473: (*s_etat_processus).erreur_execution = d_ex;
474:
475: if ((*s_etat_processus).affichage_arguments == 'Y')
476: {
477: printf("\n RRB ");
478:
479: if ((*s_etat_processus).langue == 'F')
480: {
481: printf("(rotation d'un octet vers la droite)\n\n");
482: }
483: else
484: {
485: printf("(rotate right byte)\n\n");
486: }
487:
488: printf(" 1: %s\n", d_BIN);
489: printf("-> 1: %s\n", d_BIN);
490:
491: return;
492: }
493: else if ((*s_etat_processus).test_instruction == 'Y')
494: {
495: (*s_etat_processus).nombre_arguments = -1;
496: return;
497: }
498:
499: if (test_cfsf(s_etat_processus, 31) == d_vrai)
500: {
501: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
502: {
503: return;
504: }
505: }
506:
507: l_base_pile = (*s_etat_processus).l_base_pile_last;
508: (*s_etat_processus).l_base_pile_last = NULL;
509:
510: for(i = 0; i < 8; i++)
511: {
512: instruction_rr(s_etat_processus);
513:
514: if (((*s_etat_processus).erreur_systeme != d_es) ||
515: ((*s_etat_processus).erreur_execution != d_ex))
516: {
517: break;
518: }
519: }
520:
521: if (test_cfsf(s_etat_processus, 31) == d_vrai)
522: {
523: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
524: {
525: return;
526: }
527: }
528:
529: (*s_etat_processus).l_base_pile_last = l_base_pile;
530: return;
531: }
532:
533:
534: /*
535: ================================================================================
536: Fonction 'redraw'
537: ================================================================================
538: Entrées : pointeur sur une structure struct_processus
539: --------------------------------------------------------------------------------
540: Sorties :
541: --------------------------------------------------------------------------------
542: Effets de bord : néant
543: ================================================================================
544: */
545:
546: void
547: instruction_redraw(struct_processus *s_etat_processus)
548: {
549: (*s_etat_processus).erreur_execution = d_ex;
550:
551: if ((*s_etat_processus).affichage_arguments == 'Y')
552: {
553: printf("\n REDRAW ");
554:
555: if ((*s_etat_processus).langue == 'F')
556: {
557: printf("(redessine une courbe)\n\n");
558: printf(" Aucun argument\n");
559: }
560: else
561: {
562: printf("(redraw a graphic)\n\n");
563: printf(" No argument\n");
564: }
565:
566: return;
567: }
568: else if ((*s_etat_processus).test_instruction == 'Y')
569: {
570: (*s_etat_processus).nombre_arguments = -1;
571: return;
572: }
573:
574: if (test_cfsf(s_etat_processus, 31) == d_vrai)
575: {
576: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
577: {
578: return;
579: }
580: }
581:
582: if ((*s_etat_processus).mise_a_jour_trace_requise == d_vrai)
583: {
584: (*s_etat_processus).erreur_execution = d_ex_graphique_memorise;
585: return;
586: }
587:
588: if ((*s_etat_processus).fichiers_graphiques != NULL)
589: {
590: appel_gnuplot(s_etat_processus, 'N');
591: }
592:
593: return;
594: }
595:
596:
597: /*
598: ================================================================================
599: Fonction 'remove'
600: ================================================================================
601: Entrées : pointeur sur une structure struct_processus
602: --------------------------------------------------------------------------------
603: Sorties :
604: --------------------------------------------------------------------------------
605: Effets de bord : néant
606: ================================================================================
607: */
608:
609: void
610: instruction_remove(struct_processus *s_etat_processus)
611: {
612: struct_objet *s_objet_argument;
613:
614: (*s_etat_processus).erreur_execution = d_ex;
615:
616: if ((*s_etat_processus).affichage_arguments == 'Y')
617: {
618: printf("\n REMOVE ");
619:
620: if ((*s_etat_processus).langue == 'F')
621: {
622: printf("(retrait d'une bibliothèque dynamique)\n\n");
623: }
624: else
625: {
626: printf("(remove a shared library)\n\n");
627: }
628:
629: printf(" 1: %s\n", d_SLB);
630:
631: return;
632: }
633: else if ((*s_etat_processus).test_instruction == 'Y')
634: {
635: (*s_etat_processus).nombre_arguments = -1;
636: return;
637: }
638:
639: if (test_cfsf(s_etat_processus, 31) == d_vrai)
640: {
641: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
642: {
643: return;
644: }
645: }
646:
647: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
648: &s_objet_argument) == d_erreur)
649: {
650: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
651: return;
652: }
653:
654: if ((*s_objet_argument).type == SLB)
655: {
656: /*
657: * On ne décharge que les bibliothèques qui ont été chargées dans
658: * le couple pid/tid courant.
659: */
660:
661: if (((*((struct_bibliotheque *) (*s_objet_argument).objet)).pid ==
662: getpid()) && (pthread_equal((*((struct_bibliotheque *)
663: (*s_objet_argument).objet)).tid, pthread_self()) != 0))
664: {
665: if (retrait_bibliotheque(s_etat_processus,
666: (*s_objet_argument).objet) == d_erreur)
667: {
668: liberation(s_etat_processus, s_objet_argument);
669:
670: return;
671: }
672: }
673: }
674: else
675: {
676: liberation(s_etat_processus, s_objet_argument);
677:
678: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
679: return;
680: }
681:
682: liberation(s_etat_processus, s_objet_argument);
683:
684: return;
685: }
686:
687:
688: /*
689: ================================================================================
690: Fonction 'relax'
691: ================================================================================
692: Entrées : pointeur sur une structure struct_processus
693: --------------------------------------------------------------------------------
694: Sorties :
695: --------------------------------------------------------------------------------
696: Effets de bord : néant
697: ================================================================================
698: */
699:
700: void
701: instruction_relax(struct_processus *s_etat_processus)
702: {
703: (*s_etat_processus).erreur_execution = d_ex;
704:
705: if ((*s_etat_processus).affichage_arguments == 'Y')
706: {
707: printf("\n RELAX ");
708:
709: if ((*s_etat_processus).langue == 'F')
710: {
711: printf("(ne fait rien)\n\n");
712: printf(" Aucun argument\n");
713: }
714: else
715: {
716: printf("(do nothing)\n\n");
717: printf(" No argument\n");
718: }
719:
720: return;
721: }
722: else if ((*s_etat_processus).test_instruction == 'Y')
723: {
724: (*s_etat_processus).nombre_arguments = 1;
725: return;
726: }
727:
728: /*
729: * Cette instruction ne fait rien. Elle existe pour être symétrique
730: * à l'instruction CHS et permet de traiter les équations de façon
731: * simple (Ex : '+pi'). En principe, elle n'a pas a être appelée
732: * directement par l'utilisateur.
733: */
734:
735: return;
736: }
737:
738:
739: /*
740: ================================================================================
741: Fonction 'rewind'
742: ================================================================================
743: Entrées : pointeur sur une structure struct_processus
744: --------------------------------------------------------------------------------
745: Sorties :
746: --------------------------------------------------------------------------------
747: Effets de bord : néant
748: ================================================================================
749: */
750:
751: void
752: instruction_rewind(struct_processus *s_etat_processus)
753: {
1.5 bertrand 754: struct_descripteur_fichier *descripteur;
1.1 bertrand 755:
756: struct_objet *s_objet_argument;
757:
758: (*s_etat_processus).erreur_execution = d_ex;
759:
760: if ((*s_etat_processus).affichage_arguments == 'Y')
761: {
762: printf("\n REWIND ");
763:
764: if ((*s_etat_processus).langue == 'F')
765: {
766: printf("(retour au début d'un fichier)\n\n");
767: }
768: else
769: {
770: printf("(rewind a file)\n\n");
771: }
772:
773: printf(" 1: %s\n", d_FCH);
774:
775: return;
776: }
777: else if ((*s_etat_processus).test_instruction == 'Y')
778: {
779: (*s_etat_processus).nombre_arguments = -1;
780: return;
781: }
782:
783: if (test_cfsf(s_etat_processus, 31) == d_vrai)
784: {
785: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
786: {
787: return;
788: }
789: }
790:
791: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
792: &s_objet_argument) == d_erreur)
793: {
794: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
795: return;
796: }
797:
798: if ((*s_objet_argument).type == FCH)
799: {
800: if ((descripteur = descripteur_fichier(s_etat_processus,
801: (struct_fichier *) (*s_objet_argument).objet)) == NULL)
802: {
803: return;
804: }
805:
1.5 bertrand 806: if ((*descripteur).type == 'C')
807: {
808: if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_SET) != 0)
809: {
810: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
811: return;
812: }
813: }
814: else
1.1 bertrand 815: {
816: liberation(s_etat_processus, s_objet_argument);
817:
1.5 bertrand 818: (*s_etat_processus).erreur_execution = d_ex_erreur_type_fichier;
1.1 bertrand 819: return;
820: }
821: }
822: else
823: {
824: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
825: return;
826: }
827:
828: liberation(s_etat_processus, s_objet_argument);
829:
830: return;
831: }
832:
833:
834: /*
835: ================================================================================
836: Fonction 'read'
837: ================================================================================
838: Entrées : pointeur sur une structure struct_processus
839: --------------------------------------------------------------------------------
840: Sorties :
841: --------------------------------------------------------------------------------
842: Effets de bord : néant
843: ================================================================================
844: */
845:
846: void
847: instruction_read(struct_processus *s_etat_processus)
848: {
1.6 bertrand 849: const char *queue;
850:
1.28 bertrand 851: int c;
1.8 bertrand 852: int ios;
1.84 bertrand 853: int timeout;
1.8 bertrand 854:
855: integer8 element;
1.46 bertrand 856: integer8 i;
1.8 bertrand 857: integer8 id;
1.84 bertrand 858: integer8 index;
859: integer8 longueur;
1.8 bertrand 860: integer8 position_clef;
1.77 bertrand 861:
1.46 bertrand 862: integer8 longueur_effective;
863: integer8 longueur_enregistrement;
864: integer8 longueur_questure;
865: integer8 niveau;
866: integer8 pointeur;
867: integer8 position_finale;
868: integer8 position_initiale;
869:
1.82 bertrand 870: logical1 device;
1.59 bertrand 871: logical1 format_degenere;
1.1 bertrand 872: logical1 indicateur_48;
873: logical1 presence_chaine;
874: logical1 presence_indicateur;
1.57 bertrand 875: logical1 trame_complete;
1.1 bertrand 876:
877: socklen_t longueur_adresse;
878:
1.6 bertrand 879: sqlite3_stmt *ppStmt;
880:
1.1 bertrand 881: struct flock lock;
882:
1.84 bertrand 883: struct pollfd fds[1];
884:
1.1 bertrand 885: struct sockaddr_un adresse_unix;
886: struct sockaddr_in adresse_ipv4;
1.19 bertrand 887: # ifdef IPV6
1.1 bertrand 888: struct sockaddr_in6 adresse_ipv6;
1.19 bertrand 889: # endif
1.1 bertrand 890:
1.84 bertrand 891: struct termios tc;
892:
1.1 bertrand 893: struct timespec attente;
894:
1.5 bertrand 895: struct_descripteur_fichier *descripteur;
896:
1.8 bertrand 897: struct_liste_chainee *l_element_courant;
1.59 bertrand 898: struct_liste_chainee *l_element_courant_format;
1.8 bertrand 899: struct_liste_chainee *l_element_inclus;
900:
1.1 bertrand 901: struct_objet *s_objet_adresse;
1.6 bertrand 902: struct_objet *s_objet_argument_1;
903: struct_objet *s_objet_argument_2;
1.1 bertrand 904: struct_objet *s_objet_resultat;
905: struct_objet *s_objet_type;
906:
907: unsigned char caractere;
1.8 bertrand 908: unsigned char *clef_utf8;
1.6 bertrand 909: unsigned char *commande;
1.59 bertrand 910: unsigned char *format_chaine;
1.28 bertrand 911: unsigned char *ptr;
1.1 bertrand 912: unsigned char *tampon_lecture;
913: unsigned char *tampon;
1.8 bertrand 914: unsigned char *tampon2;
1.84 bertrand 915: unsigned char *tampon3;
916:
917: int vitesses[] =
918: {
919: 50, 75, 110, 134, 150, 200, 300, 600,
920: 1200, 1800, 2400, 4800, 9600, 19200, 38400,
921: #ifdef B57600
922: 57600,
923: #endif
924: #ifdef B115200
925: 115200,
926: #endif
927: #ifdef B230400
928: 230400,
929: #endif
930: 0
931: };
932:
933: tcflag_t vitesses_constantes[] =
934: {
935: B50, B75, B110, B134, B150, B200, B300, B600,
936: B1200, B1800, B2400, B4800, B9600, B19200, B38400,
937: #ifdef B57600
938: B57600,
939: #endif
940: #ifdef B115200
941: B115200,
942: #endif
943: #ifdef B230400
944: B230400,
945: #endif
946: 0
947: };
1.1 bertrand 948:
949: (*s_etat_processus).erreur_execution = d_ex;
950:
951: if ((*s_etat_processus).affichage_arguments == 'Y')
952: {
953: printf("\n READ ");
954:
955: if ((*s_etat_processus).langue == 'F')
956: {
957: printf("(lecture d'un enregistrement d'un fichier)\n\n");
958: }
959: else
960: {
961: printf("(read a record of a file)\n\n");
962: }
963:
1.6 bertrand 964: printf(" 1: %s, %s\n\n", d_FCH, d_SCK);
1.1 bertrand 965:
1.8 bertrand 966: printf(" 2: %s, %s\n", d_INT, d_CHN);
1.6 bertrand 967: printf(" 1: %s\n", d_FCH);
1.1 bertrand 968: return;
969: }
970: else if ((*s_etat_processus).test_instruction == 'Y')
971: {
972: (*s_etat_processus).nombre_arguments = -1;
973: return;
974: }
975:
976: if (test_cfsf(s_etat_processus, 31) == d_vrai)
977: {
1.6 bertrand 978: if ((*s_etat_processus).l_base_pile == NULL)
1.1 bertrand 979: {
1.6 bertrand 980: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1.1 bertrand 981: return;
982: }
1.6 bertrand 983:
984: if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
985: {
986: if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
987: .donnee).objet)).acces == 'S')
988: {
989: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
990: {
991: return;
992: }
993: }
994: else
995: {
996: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
997: {
998: return;
999: }
1000: }
1001: }
1002: else
1003: {
1004: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
1005: {
1006: return;
1007: }
1008: }
1.1 bertrand 1009: }
1010:
1011: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.6 bertrand 1012: &s_objet_argument_1) == d_erreur)
1.1 bertrand 1013: {
1014: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1015: return;
1016: }
1017:
1.6 bertrand 1018: if ((*s_objet_argument_1).type == FCH)
1.1 bertrand 1019: {
1.5 bertrand 1020: if ((descripteur = descripteur_fichier(s_etat_processus,
1.6 bertrand 1021: (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
1.5 bertrand 1022: {
1023: return;
1024: }
1025:
1.1 bertrand 1026: /*
1027: * Vérification des verrous
1028: */
1029:
1030: lock.l_type = F_RDLCK;
1031: lock.l_whence = SEEK_SET;
1032: lock.l_start = 0;
1033: lock.l_len = 0;
1034: lock.l_pid = getpid();
1035:
1.5 bertrand 1036: if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
1037: == -1)
1.1 bertrand 1038: {
1.6 bertrand 1039: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1040:
1041: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1042: return;
1043: }
1044:
1045: if (lock.l_type != F_UNLCK)
1046: {
1.6 bertrand 1047: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1048:
1049: (*s_etat_processus).erreur_execution =
1050: d_ex_fichier_verrouille;
1051: return;
1052: }
1053:
1054: /*
1055: * Vérification de l'autorisation de lecture
1056: */
1057:
1.6 bertrand 1058: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).protection
1059: == 'W')
1.1 bertrand 1060: {
1.6 bertrand 1061: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1062:
1063: (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
1064: return;
1065: }
1.6 bertrand 1066: else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).protection
1.1 bertrand 1067: == 'N')
1068: {
1.5 bertrand 1069: if ((*descripteur).type == 'C')
1.1 bertrand 1070: {
1.5 bertrand 1071: if (fflush((*descripteur).descripteur_c) != 0)
1072: {
1073: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1074: return;
1075: }
1.1 bertrand 1076: }
1077: }
1078:
1.6 bertrand 1079: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
1.1 bertrand 1080: {
1081: /*
1082: * Fichiers formatés
1083: */
1084:
1.6 bertrand 1085: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1086: == 'S')
1.1 bertrand 1087: {
1088: /*
1089: * Fichiers séquentiels
1090: */
1091:
1.75 bertrand 1092: longueur_questure = 4096;
1.1 bertrand 1093:
1.76 bertrand 1094: if ((tampon_lecture = malloc(((size_t) longueur_questure) *
1.1 bertrand 1095: sizeof(unsigned char))) == NULL)
1096: {
1097: (*s_etat_processus).erreur_systeme =
1098: d_es_allocation_memoire;
1099: return;
1100: }
1101:
1.5 bertrand 1102: BUG(((*descripteur).type != 'C'), uprintf("Bad filtype !\n"));
1103:
1104: if ((position_initiale = ftell((*descripteur).descripteur_c))
1105: == -1)
1.1 bertrand 1106: {
1107: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1108: return;
1109: }
1110:
1111: do
1112: {
1.76 bertrand 1113: longueur_effective = (integer8) fread(tampon_lecture,
1114: sizeof(unsigned char), (size_t) longueur_questure,
1.5 bertrand 1115: (*descripteur).descripteur_c);
1.1 bertrand 1116:
1117: pointeur = 0;
1118: presence_indicateur = d_faux;
1119:
1120: while(pointeur < longueur_effective)
1121: {
1122: if (tampon_lecture[pointeur] == '{')
1123: {
1124: presence_indicateur = d_vrai;
1125: break;
1126: }
1127:
1128: position_initiale++;
1129: pointeur++;
1130: }
1131:
1132: if (presence_indicateur == d_vrai)
1133: {
1134: break;
1135: }
1136: } while(longueur_effective == longueur_questure);
1137:
1138: if (presence_indicateur == d_faux)
1139: {
1.6 bertrand 1140: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1141: free(tampon_lecture);
1142:
1143: (*s_etat_processus).erreur_execution =
1144: d_ex_fin_de_fichier_atteinte;
1145: return;
1146: }
1147:
1148: position_finale = position_initiale + 1;
1149: presence_chaine = d_faux;
1150: niveau = 1;
1151:
1.77 bertrand 1152: if (fseek((*descripteur).descripteur_c, (long) position_finale,
1.5 bertrand 1153: SEEK_SET) != 0)
1.1 bertrand 1154: {
1.6 bertrand 1155: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1156: free(tampon_lecture);
1157:
1158: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1159: return;
1160: }
1161:
1162: do
1163: {
1.76 bertrand 1164: longueur_effective = (integer8) fread(tampon_lecture,
1165: sizeof(unsigned char), (size_t) longueur_questure,
1.5 bertrand 1166: (*descripteur).descripteur_c);
1.1 bertrand 1167:
1168: pointeur = 0;
1169: presence_indicateur = d_faux;
1170:
1171: while(pointeur < longueur_effective)
1172: {
1173: if (tampon_lecture[pointeur] == '"')
1174: {
1.7 bertrand 1175: if (pointeur > 0)
1176: {
1177: if (tampon_lecture[pointeur - 1] != '\\')
1178: {
1179: presence_chaine = (presence_chaine ==
1180: d_vrai) ? d_faux : d_vrai;
1181: }
1182: }
1183: else
1184: {
1185: presence_chaine = (presence_chaine == d_vrai)
1186: ? d_faux : d_vrai;
1187: }
1.1 bertrand 1188: }
1189: else
1190: {
1191: if (presence_chaine == d_faux)
1192: {
1193: if (tampon_lecture[pointeur] == '{')
1194: {
1195: niveau++;
1196: }
1197: else if (tampon_lecture[pointeur] == '}')
1198: {
1199: niveau--;
1200: }
1201: }
1202: }
1203:
1204: position_finale++;
1205: pointeur++;
1206:
1207: if (niveau == 0)
1208: {
1209: presence_indicateur = d_vrai;
1210: break;
1211: }
1212: }
1213:
1214: if (presence_indicateur == d_vrai)
1215: {
1216: break;
1217: }
1218: } while(longueur_effective == longueur_questure);
1219:
1220: if (presence_indicateur == d_faux)
1221: {
1.6 bertrand 1222: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1223: free(tampon_lecture);
1224:
1225: (*s_etat_processus).erreur_execution =
1226: d_ex_fin_de_fichier_atteinte;
1227: return;
1228: }
1229:
1230: free(tampon_lecture);
1231: longueur_enregistrement = position_finale - position_initiale;
1232:
1.76 bertrand 1233: if ((tampon_lecture = malloc(((size_t)
1234: (longueur_enregistrement + 1)) *
1.1 bertrand 1235: sizeof(unsigned char))) == NULL)
1236: {
1237: (*s_etat_processus).erreur_systeme =
1238: d_es_allocation_memoire;
1239: return;
1240: }
1241:
1.77 bertrand 1242: if (fseek((*descripteur).descripteur_c,
1243: (long) position_initiale, SEEK_SET) != 0)
1.1 bertrand 1244: {
1.6 bertrand 1245: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1246: free(tampon_lecture);
1247:
1248: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1249: return;
1250: }
1251:
1.76 bertrand 1252: longueur_effective = (integer8) fread(tampon_lecture,
1253: sizeof(unsigned char), (size_t) longueur_enregistrement,
1.5 bertrand 1254: (*descripteur).descripteur_c);
1.1 bertrand 1255:
1256: if (longueur_effective != longueur_enregistrement)
1257: {
1258: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1259: return;
1260: }
1261:
1262: tampon_lecture[longueur_enregistrement] = d_code_fin_chaine;
1263: tampon = (*s_etat_processus).instruction_courante;
1.5 bertrand 1264:
1265: if (((*s_etat_processus).instruction_courante =
1266: transliteration(s_etat_processus, tampon_lecture,
1267: "UTF-8", d_locale)) == NULL)
1268: {
1.6 bertrand 1269: (*s_etat_processus).instruction_courante = tampon;
1270: liberation(s_etat_processus, s_objet_argument_1);
1.5 bertrand 1271: free(tampon_lecture);
1272: return;
1273: }
1.1 bertrand 1274:
1275: indicateur_48 = test_cfsf(s_etat_processus, 48);
1276: cf(s_etat_processus, 48);
1277:
1278: recherche_type(s_etat_processus);
1.5 bertrand 1279: free((*s_etat_processus).instruction_courante);
1.1 bertrand 1280:
1281: if ((*s_etat_processus).erreur_execution != d_ex)
1282: {
1.6 bertrand 1283: if (indicateur_48 == d_vrai)
1284: {
1285: sf(s_etat_processus, 48);
1286: }
1287: else
1288: {
1289: cf(s_etat_processus, 48);
1290: }
1291:
1.1 bertrand 1292: (*s_etat_processus).instruction_courante = tampon;
1293: free(tampon_lecture);
1294:
1.6 bertrand 1295: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1296: return;
1297: }
1298:
1299: if (indicateur_48 == d_vrai)
1300: {
1301: sf(s_etat_processus, 48);
1302: }
1303: else
1304: {
1305: cf(s_etat_processus, 48);
1306: }
1307:
1308: (*s_etat_processus).instruction_courante = tampon;
1309: free(tampon_lecture);
1310: }
1.6 bertrand 1311: else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1.1 bertrand 1312: == 'D')
1313: {
1.6 bertrand 1314: BUG(((*descripteur).type != 'S'), uprintf("Bad filtype !\n"));
1315:
1316: if (depilement(s_etat_processus, &((*s_etat_processus)
1317: .l_base_pile), &s_objet_argument_2) == d_erreur)
1318: {
1319: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1320: return;
1321: }
1322:
1323: if ((*s_objet_argument_2).type != INT)
1324: {
1325: liberation(s_etat_processus, s_objet_argument_1);
1326: liberation(s_etat_processus, s_objet_argument_2);
1327:
1328: (*s_etat_processus).erreur_execution =
1329: d_ex_erreur_type_argument;
1330: return;
1331: }
1332:
1333: if (alsprintf(&commande, "select data from data where "
1334: "id = %lld", (*((integer8 *) (*s_objet_argument_2)
1335: .objet))) < 0)
1336: {
1337: (*s_etat_processus).erreur_systeme =
1338: d_es_allocation_memoire;
1339: return;
1340: }
1341:
1342: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1343: commande, (int) strlen(commande), &ppStmt, &queue)
1.6 bertrand 1344: != SQLITE_OK)
1345: {
1346: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1347: return;
1348: }
1.68 bertrand 1349:
1350: attente.tv_sec = 0;
1351: attente.tv_nsec = GRANULARITE_us * 1000;
1352:
1353: do
1.6 bertrand 1354: {
1.68 bertrand 1355: ios = sqlite3_step(ppStmt);
1.6 bertrand 1356:
1.68 bertrand 1357: switch(ios)
1.6 bertrand 1358: {
1.68 bertrand 1359: case SQLITE_ROW:
1.6 bertrand 1360: {
1.68 bertrand 1361: // Résultat attendu
1362: break;
1.6 bertrand 1363: }
1364:
1.68 bertrand 1365: case SQLITE_DONE:
1366: {
1367: // Aucun enregistrement
1368: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1369: {
1370: (*s_etat_processus).erreur_systeme =
1371: d_es_erreur_fichier;
1372: return;
1373: }
1374:
1375: free(commande);
1.6 bertrand 1376:
1.68 bertrand 1377: liberation(s_etat_processus, s_objet_argument_1);
1378: liberation(s_etat_processus, s_objet_argument_2);
1379:
1380: (*s_etat_processus).erreur_execution =
1381: d_ex_enregistrement_inexistant;
1382: return;
1383: }
1.6 bertrand 1384:
1.68 bertrand 1385: case SQLITE_BUSY:
1386: case SQLITE_LOCKED:
1387: {
1388: nanosleep(&attente, NULL);
1389: INCR_GRANULARITE(attente.tv_nsec);
1390: break;
1391: }
1.6 bertrand 1392:
1.68 bertrand 1393: default:
1394: {
1395: (*s_etat_processus).erreur_systeme =
1396: d_es_erreur_fichier;
1397: return;
1398: }
1.6 bertrand 1399: }
1.68 bertrand 1400: } while(ios != SQLITE_ROW);
1.6 bertrand 1401:
1402: if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT)
1403: {
1404: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1405: return;
1406: }
1407:
1408: tampon = (*s_etat_processus).instruction_courante;
1409:
1410: if ((tampon_lecture = (unsigned char *)
1411: sqlite3_column_text(ppStmt, 0)) == NULL)
1412: {
1413: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1414: return;
1415: }
1416:
1417: if (((*s_etat_processus).instruction_courante =
1418: transliteration(s_etat_processus, tampon_lecture,
1419: "UTF-8", d_locale)) == NULL)
1420: {
1421: (*s_etat_processus).instruction_courante = tampon;
1422:
1423: liberation(s_etat_processus, s_objet_argument_1);
1424: liberation(s_etat_processus, s_objet_argument_2);
1425: free(commande);
1426: return;
1427: }
1428:
1429: indicateur_48 = test_cfsf(s_etat_processus, 48);
1430: cf(s_etat_processus, 48);
1431:
1432: recherche_type(s_etat_processus);
1433:
1434: if ((*s_etat_processus).erreur_execution != d_ex)
1435: {
1436: if (indicateur_48 == d_vrai)
1437: {
1438: sf(s_etat_processus, 48);
1439: }
1440: else
1441: {
1442: cf(s_etat_processus, 48);
1443: }
1444:
1445: liberation(s_etat_processus, s_objet_argument_1);
1446: liberation(s_etat_processus, s_objet_argument_2);
1447:
1448: free((*s_etat_processus).instruction_courante);
1449: free(commande);
1.8 bertrand 1450:
1451: (*s_etat_processus).instruction_courante = tampon;
1.6 bertrand 1452: return;
1453: }
1454:
1455: if (indicateur_48 == d_vrai)
1456: {
1457: sf(s_etat_processus, 48);
1458: }
1459: else
1460: {
1461: cf(s_etat_processus, 48);
1462: }
1463:
1464: free((*s_etat_processus).instruction_courante);
1465: liberation(s_etat_processus, s_objet_argument_2);
1466: (*s_etat_processus).instruction_courante = tampon;
1467:
1468: if (sqlite3_step(ppStmt) != SQLITE_DONE)
1469: {
1470: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1471: return;
1472: }
1473:
1474: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1475: {
1476: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1477: return;
1478: }
1479:
1480: free(commande);
1.1 bertrand 1481: }
1482: else
1483: {
1.8 bertrand 1484: BUG(((*descripteur).type != 'S'), uprintf("Bad filtype !\n"));
1485:
1486: if (depilement(s_etat_processus, &((*s_etat_processus)
1487: .l_base_pile), &s_objet_argument_2) == d_erreur)
1488: {
1489: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1490: return;
1491: }
1492:
1493: if ((*s_objet_argument_2).type != CHN)
1494: {
1495: liberation(s_etat_processus, s_objet_argument_1);
1496: liberation(s_etat_processus, s_objet_argument_2);
1497:
1498: (*s_etat_processus).erreur_execution =
1499: d_ex_erreur_type_argument;
1500: return;
1501: }
1502:
1503: // Récupération de la position de la clef
1504:
1505: if (alsprintf(&commande, "select key from control "
1506: "where id = 1") < 0)
1507: {
1508: (*s_etat_processus).erreur_systeme =
1509: d_es_allocation_memoire;
1510: return;
1511: }
1512:
1513: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1514: commande, (int) strlen(commande), &ppStmt, &queue)
1.8 bertrand 1515: != SQLITE_OK)
1516: {
1517: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1518: return;
1519: }
1520:
1.68 bertrand 1521: attente.tv_sec = 0;
1522: attente.tv_nsec = GRANULARITE_us * 1000;
1523:
1524: do
1.8 bertrand 1525: {
1.68 bertrand 1526: ios = sqlite3_step(ppStmt);
1527:
1528: if (ios == SQLITE_ROW)
1529: {
1530: break;
1531: }
1532: else if ((ios == SQLITE_BUSY) || (ios == SQLITE_LOCKED))
1533: {
1534: nanosleep(&attente, NULL);
1535: INCR_GRANULARITE(attente.tv_nsec);
1536: }
1537: else
1538: {
1539: (*s_etat_processus).erreur_systeme =
1540: d_es_erreur_fichier;
1541: return;
1542: }
1543: } while(ios != SQLITE_ROW);
1.8 bertrand 1544:
1545: if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
1546: {
1547: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1548: return;
1549: }
1550:
1551: position_clef = sqlite3_column_int64(ppStmt, 0);
1552:
1553: if (sqlite3_step(ppStmt) != SQLITE_DONE)
1554: {
1555: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1556: return;
1557: }
1558:
1559: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1560: {
1561: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1562: return;
1563: }
1564:
1565: free(commande);
1566:
1567: if ((clef_utf8 = transliteration(s_etat_processus,
1568: (unsigned char *) (*s_objet_argument_2).objet,
1569: d_locale, "UTF-8")) == NULL)
1570: {
1571: liberation(s_etat_processus, s_objet_argument_1);
1572: liberation(s_etat_processus, s_objet_argument_2);
1573:
1574: return;
1575: }
1576:
1577: // Récupération de l'identifiant de la clef
1578:
1579: if (alsprintf(&commande, "select id from key where key = "
1580: "'{ \"%s\" }'", clef_utf8) < 0)
1581: {
1582: (*s_etat_processus).erreur_systeme =
1583: d_es_allocation_memoire;
1584: return;
1585: }
1586:
1587: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1588: commande, (int) strlen(commande), &ppStmt, &queue)
1.8 bertrand 1589: != SQLITE_OK)
1590: {
1591: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1592: return;
1593: }
1594:
1.68 bertrand 1595: attente.tv_sec = 0;
1596: attente.tv_nsec = GRANULARITE_us * 1000;
1597:
1598: do
1.8 bertrand 1599: {
1.68 bertrand 1600: ios = sqlite3_step(ppStmt);
1.8 bertrand 1601:
1.68 bertrand 1602: switch(ios)
1.8 bertrand 1603: {
1.68 bertrand 1604: case SQLITE_ROW:
1.8 bertrand 1605: {
1.68 bertrand 1606: // Résultat attendu : une clef correspond.
1607: break;
1.8 bertrand 1608: }
1609:
1.68 bertrand 1610: case SQLITE_DONE:
1611: {
1612: // Aucun enregistrement
1613: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1614: {
1615: (*s_etat_processus).erreur_systeme =
1616: d_es_erreur_fichier;
1617: return;
1618: }
1619:
1620: free(clef_utf8);
1621: free(commande);
1622:
1623: liberation(s_etat_processus, s_objet_argument_1);
1624: liberation(s_etat_processus, s_objet_argument_2);
1.8 bertrand 1625:
1.68 bertrand 1626: (*s_etat_processus).erreur_execution =
1627: d_ex_enregistrement_inexistant;
1628: return;
1629: }
1.8 bertrand 1630:
1.68 bertrand 1631: case SQLITE_BUSY:
1632: case SQLITE_LOCKED:
1633: {
1634: nanosleep(&attente, NULL);
1635: INCR_GRANULARITE(attente.tv_nsec);
1636: break;
1637: }
1.8 bertrand 1638:
1.68 bertrand 1639: default:
1640: {
1641: (*s_etat_processus).erreur_systeme =
1642: d_es_erreur_fichier;
1643: return;
1644: }
1.8 bertrand 1645: }
1.68 bertrand 1646: } while(ios != SQLITE_ROW);
1.8 bertrand 1647:
1648: if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
1649: {
1650: free(clef_utf8);
1651: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1652: return;
1653: }
1654:
1655: id = sqlite3_column_int64(ppStmt, 0);
1656:
1657: if (sqlite3_step(ppStmt) != SQLITE_DONE)
1658: {
1659: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1660: return;
1661: }
1662:
1663: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1664: {
1665: (*s_etat_processus).erreur_systeme =
1666: d_es_erreur_fichier;
1667: return;
1668: }
1669:
1670: free(commande);
1671:
1672: if (alsprintf(&commande, "select data from data where "
1673: "key_id = %lld order by sequence asc", id) < 0)
1674: {
1675: (*s_etat_processus).erreur_systeme =
1676: d_es_allocation_memoire;
1677: return;
1678: }
1679:
1680: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1681: commande, (int) strlen(commande), &ppStmt, &queue)
1.8 bertrand 1682: != SQLITE_OK)
1683: {
1684: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1685: return;
1686: }
1687:
1688: element = 1;
1689:
1.68 bertrand 1690: attente.tv_sec = 0;
1691: attente.tv_nsec = GRANULARITE_us * 1000;
1692:
1.8 bertrand 1693: do
1694: {
1695: switch(ios = sqlite3_step(ppStmt))
1696: {
1697: case SQLITE_ROW:
1698: {
1699: // Donnée supplémentaire
1700:
1701: if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT)
1702: {
1703: (*s_etat_processus).erreur_systeme =
1704: d_es_erreur_fichier;
1705: return;
1706: }
1707:
1708: tampon = (*s_etat_processus).instruction_courante;
1709:
1710: if ((tampon_lecture = (unsigned char *)
1711: sqlite3_column_text(ppStmt, 0)) == NULL)
1712: {
1713: (*s_etat_processus).erreur_systeme =
1714: d_es_erreur_fichier;
1715: return;
1716: }
1717:
1718: if (((*s_etat_processus).instruction_courante =
1719: transliteration(s_etat_processus,
1720: tampon_lecture,
1721: "UTF-8", d_locale)) == NULL)
1722: {
1723: (*s_etat_processus).instruction_courante =
1724: tampon;
1725:
1726: liberation(s_etat_processus,
1727: s_objet_argument_1);
1728: liberation(s_etat_processus,
1729: s_objet_argument_2);
1730:
1731: free(commande);
1732: free(clef_utf8);
1733: return;
1734: }
1735:
1736: indicateur_48 = test_cfsf(s_etat_processus, 48);
1737: cf(s_etat_processus, 48);
1738:
1739: recherche_type(s_etat_processus);
1740:
1741: if ((*s_etat_processus).erreur_execution != d_ex)
1742: {
1743: if (indicateur_48 == d_vrai)
1744: {
1745: sf(s_etat_processus, 48);
1746: }
1747: else
1748: {
1749: cf(s_etat_processus, 48);
1750: }
1751:
1752: liberation(s_etat_processus,
1753: s_objet_argument_1);
1754: liberation(s_etat_processus,
1755: s_objet_argument_2);
1756:
1757: free((*s_etat_processus).instruction_courante);
1758: free(commande);
1759: free(clef_utf8);
1760:
1761: (*s_etat_processus).instruction_courante =
1762: tampon;
1763: return;
1764: }
1765:
1766: if (indicateur_48 == d_vrai)
1767: {
1768: sf(s_etat_processus, 48);
1769: }
1770: else
1771: {
1772: cf(s_etat_processus, 48);
1773: }
1774:
1775: free((*s_etat_processus).instruction_courante);
1776: (*s_etat_processus).instruction_courante = tampon;
1777:
1778: element++;
1779:
1780: // Inscription de la clef
1781:
1782: if (element == position_clef)
1783: {
1784: if (((*s_etat_processus).instruction_courante =
1785: transliteration(s_etat_processus,
1786: clef_utf8, "UTF-8", d_locale)) == NULL)
1787: {
1788: (*s_etat_processus).instruction_courante =
1789: tampon;
1790:
1791: liberation(s_etat_processus,
1792: s_objet_argument_1);
1793: liberation(s_etat_processus,
1794: s_objet_argument_2);
1795:
1796: free(commande);
1797: free(clef_utf8);
1798: return;
1799: }
1800:
1801: if (alsprintf(&tampon2, "{ \"%s\" }",
1802: (*s_etat_processus)
1803: .instruction_courante) < 0)
1804: {
1805: (*s_etat_processus).erreur_systeme =
1806: d_es_allocation_memoire;
1807: return;
1808: }
1809:
1810: free((*s_etat_processus).instruction_courante);
1811: (*s_etat_processus).instruction_courante
1812: = tampon2;
1813:
1814: indicateur_48 = test_cfsf(s_etat_processus, 48);
1815: cf(s_etat_processus, 48);
1816:
1817: recherche_type(s_etat_processus);
1818:
1819: if ((*s_etat_processus).erreur_execution
1820: != d_ex)
1821: {
1822: if (indicateur_48 == d_vrai)
1823: {
1824: sf(s_etat_processus, 48);
1825: }
1826: else
1827: {
1828: cf(s_etat_processus, 48);
1829: }
1830:
1831: liberation(s_etat_processus,
1832: s_objet_argument_1);
1833: liberation(s_etat_processus,
1834: s_objet_argument_2);
1835:
1836: free((*s_etat_processus)
1837: .instruction_courante);
1838: free(commande);
1839: free(clef_utf8);
1840:
1841: (*s_etat_processus).instruction_courante =
1842: tampon;
1843: return;
1844: }
1845:
1846: if (indicateur_48 == d_vrai)
1847: {
1848: sf(s_etat_processus, 48);
1849: }
1850: else
1851: {
1852: cf(s_etat_processus, 48);
1853: }
1854:
1855: free((*s_etat_processus).instruction_courante);
1856: (*s_etat_processus).instruction_courante =
1857: tampon;
1858:
1859: element++;
1860: }
1861:
1862: break;
1863: }
1864:
1865: case SQLITE_DONE:
1866: {
1867: // Fin de la liste
1868: break;
1869: }
1870:
1.68 bertrand 1871: case SQLITE_BUSY:
1872: case SQLITE_LOCKED:
1873: {
1874: nanosleep(&attente, NULL);
1875: INCR_GRANULARITE(attente.tv_nsec);
1876: break;
1877: }
1878:
1.8 bertrand 1879: default:
1880: {
1881: (*s_etat_processus).erreur_systeme =
1882: d_es_erreur_fichier;
1883: return;
1884: }
1885: }
1886: } while(ios != SQLITE_DONE);
1887:
1888: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1889: {
1890: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1891: return;
1892: }
1893:
1894: free(commande);
1895: free(clef_utf8);
1896:
1897: liberation(s_etat_processus, s_objet_argument_2);
1898:
1899: if ((s_objet_resultat = allocation(s_etat_processus, LST))
1900: == NULL)
1901: {
1902: (*s_etat_processus).erreur_systeme =
1903: d_es_allocation_memoire;
1904: return;
1905: }
1906:
1907: l_element_courant = NULL;
1.9 bertrand 1908: l_element_inclus = NULL;
1.8 bertrand 1909:
1910: for(element--; element > 0; element--)
1911: {
1912: if (depilement(s_etat_processus, &((*s_etat_processus)
1913: .l_base_pile), &s_objet_argument_2) == d_erreur)
1914: {
1915: (*s_etat_processus).erreur_systeme =
1916: d_es_erreur_fichier;
1917: return;
1918: }
1919:
1920: if ((*s_objet_argument_2).type != LST)
1921: {
1922: (*s_etat_processus).erreur_systeme =
1923: d_es_erreur_fichier;
1924: return;
1925: }
1926:
1927: l_element_inclus = (*s_objet_argument_2).objet;
1928:
1929: if (l_element_inclus != NULL)
1930: {
1931: while(l_element_inclus != NULL)
1932: {
1933: if ((*l_element_inclus).suivant == NULL)
1934: {
1935: (*l_element_inclus).suivant = l_element_courant;
1936: break;
1937: }
1938:
1939: l_element_inclus = (*l_element_inclus).suivant;
1940: }
1941:
1942: l_element_courant = (*s_objet_argument_2).objet;
1943: (*s_objet_argument_2).objet = NULL;
1944: }
1945:
1946: liberation(s_etat_processus, s_objet_argument_2);
1947: }
1948:
1949: (*s_objet_resultat).objet = l_element_inclus;
1950:
1951: if (empilement(s_etat_processus,
1952: &((*s_etat_processus).l_base_pile),
1953: s_objet_resultat) == d_erreur)
1954: {
1955: return;
1956: }
1.1 bertrand 1957: }
1958: }
1.6 bertrand 1959: else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
1.1 bertrand 1960: == 'Y')
1961: {
1962: /*
1963: * Fichiers non formatés
1964: */
1.46 bertrand 1965:
1966: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1967: == 'S')
1968: {
1969: /*
1970: * Fichiers séquentiels
1971: *
1972: * Les fichiers séquentiels non formatés contiennent comme
1973: * les fichiers séquentiels formatés leurs enregistrements
1974: * sous la forme de listes les unes derrières les autres.
1975: *
1976: * Le quartet de poids fort du premier octet à lire
1977: * doit donc être égal à 0100. Si ce n'est pas le cas,
1978: * il sera impossible de lire le fichier et on renvoie
1979: * immédiatement une erreur. Si on lit dans le fichier
1980: * la valeur attendue, on récupère la longueur en octet
1981: * de l'enregistrement puis on le lit.
1982: */
1983:
1984: BUG(((*descripteur).type != 'C'), uprintf("Bad filtype !\n"));
1985:
1.72 bertrand 1986: if ((s_objet_resultat = lecture_fichier_non_formate(
1987: s_etat_processus, (*descripteur).descripteur_c, -1,
1988: d_faux)) == NULL)
1.46 bertrand 1989: {
1990: return;
1991: }
1992:
1.72 bertrand 1993: if (empilement(s_etat_processus,
1994: &((*s_etat_processus).l_base_pile),
1995: s_objet_resultat) == d_erreur)
1.46 bertrand 1996: {
1997: return;
1998: }
1999: }
1.1 bertrand 2000: }
2001: else
2002: {
2003: /*
2004: * Fichiers de type FLOW
2005: */
1.28 bertrand 2006:
2007: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
2008: == 'S')
2009: {
2010: /*
2011: * Fichiers séquentiels
2012: */
2013:
2014: BUG(((*descripteur).type != 'C'), uprintf("Bad filtype !\n"));
2015: longueur_enregistrement = 0;
1.84 bertrand 2016:
1.82 bertrand 2017: device = d_faux;
1.28 bertrand 2018:
2019: if ((position_initiale = ftell((*descripteur).descripteur_c))
2020: == -1)
2021: {
1.82 bertrand 2022: if (errno == ESPIPE)
2023: {
2024: device = d_vrai;
2025: }
2026: else
2027: {
2028: (*s_etat_processus).erreur_systeme =
2029: d_es_erreur_fichier;
2030: return;
2031: }
1.28 bertrand 2032: }
2033:
1.59 bertrand 2034: l_element_courant_format = (struct_liste_chainee *)
2035: (*(*((struct_fichier *) (*s_objet_argument_1).objet))
2036: .format).objet;
2037: l_element_courant = NULL;
1.28 bertrand 2038:
2039: if ((s_objet_resultat = allocation(s_etat_processus, LST))
2040: == NULL)
2041: {
2042: (*s_etat_processus).erreur_systeme =
2043: d_es_allocation_memoire;
2044: return;
2045: }
2046:
1.59 bertrand 2047: while(l_element_courant_format != NULL)
1.28 bertrand 2048: {
1.59 bertrand 2049: if ((*(*l_element_courant_format).donnee).type != CHN)
2050: {
2051: liberation(s_etat_processus, s_objet_argument_1);
2052: liberation(s_etat_processus, s_objet_resultat);
2053:
2054: (*s_etat_processus).erreur_execution =
2055: d_ex_erreur_type_argument;
2056: return;
2057: }
2058:
2059: if ((format_chaine = conversion_majuscule((unsigned char *)
2060: (*(*l_element_courant_format).donnee).objet))
2061: == NULL)
2062: {
2063: (*s_etat_processus).erreur_systeme =
2064: d_es_allocation_memoire;
2065: return;
2066: }
2067:
2068: if (strncmp("LENGTH*(", format_chaine, 8) != 0)
2069: {
2070: liberation(s_etat_processus, s_objet_argument_1);
2071: liberation(s_etat_processus, s_objet_resultat);
2072: free(format_chaine);
2073:
2074: (*s_etat_processus).erreur_execution =
2075: d_ex_erreur_format_fichier;
2076: return;
2077: }
2078:
1.76 bertrand 2079: longueur = (integer8) strlen(format_chaine);
1.59 bertrand 2080:
1.60 bertrand 2081: if (format_chaine[longueur - 1] != ')')
1.59 bertrand 2082: {
2083: liberation(s_etat_processus, s_objet_argument_1);
2084: liberation(s_etat_processus, s_objet_resultat);
2085: free(format_chaine);
2086:
2087: (*s_etat_processus).erreur_execution =
2088: d_ex_erreur_format_fichier;
2089: return;
2090: }
2091:
2092: format_chaine[longueur] = d_code_fin_chaine;
2093:
2094: if (format_chaine[8] == '*')
2095: {
2096: format_degenere = d_vrai;
2097: }
2098: else
2099: {
2100: // Détermination de la longueur
2101: format_degenere = d_faux;
2102:
1.77 bertrand 2103: if (sscanf(&(format_chaine[8]), "%lld", &longueur) != 1)
1.59 bertrand 2104: {
2105: liberation(s_etat_processus, s_objet_argument_1);
2106: liberation(s_etat_processus, s_objet_resultat);
2107: free(format_chaine);
2108:
2109: (*s_etat_processus).erreur_execution =
2110: d_ex_erreur_format_fichier;
2111: return;
2112: }
2113: }
2114:
2115: free(format_chaine);
1.84 bertrand 2116: tampon3 = NULL;
1.59 bertrand 2117:
2118: if (format_degenere == d_vrai)
2119: {
1.84 bertrand 2120: if (device == d_vrai)
2121: {
2122: longueur_questure = 4096;
2123: index = 0;
2124:
2125: if ((tampon3 = malloc(((size_t) longueur_questure) *
2126: sizeof(unsigned char))) == NULL)
2127: {
2128: (*s_etat_processus).erreur_systeme =
2129: d_es_allocation_memoire;
2130: return;
2131: }
2132:
2133: tampon3[index] = d_code_fin_chaine;
2134:
2135: fds[0].fd = fileno((*descripteur).descripteur_c);
2136: fds[0].events = POLLIN;
2137: fds[0].revents = 0;
2138:
2139: tcgetattr(fileno((*descripteur).descripteur_c),
2140: &tc);
2141: timeout = 0;
2142:
2143: for(i = 0; vitesses[i] != 0; i++)
2144: {
2145: if (cfgetispeed(&tc) == vitesses_constantes[i])
2146: {
2147: // La durée entre deux caractères sur le
2148: // périphérique série ne doit pas dépasser
2149: // la moitié de la durée de transmission
2150: // d'un caractère complet.
2151:
2152: timeout = (int) (((double) 1000) /
2153: (((double) vitesses_constantes[i]) /
2154: 4));
2155: break;
2156: }
2157: }
2158: }
2159:
1.59 bertrand 2160: do
2161: {
1.84 bertrand 2162: if (device == d_vrai)
2163: {
2164: if (poll(fds, 1, timeout) == 0)
2165: {
2166: break;
2167: }
2168: }
2169:
1.59 bertrand 2170: c = getc((*descripteur).descripteur_c);
2171: longueur_enregistrement++;
1.84 bertrand 2172:
2173: if (device == d_vrai)
2174: {
2175: if (longueur_enregistrement >=
2176: longueur_questure)
2177: {
2178: if ((tampon3 = realloc(tampon3,
2179: (size_t) (longueur_questure *= 2)))
2180: == NULL)
2181: {
2182: (*s_etat_processus).erreur_systeme =
2183: d_es_allocation_memoire;
2184: return;
2185: }
2186: }
2187:
2188: tampon3[index++] = (unsigned char) c;
2189: }
2190: } while(c != EOF);
1.59 bertrand 2191:
1.82 bertrand 2192: if (device == d_faux)
1.59 bertrand 2193: {
1.82 bertrand 2194: if (fseek((*descripteur).descripteur_c,
2195: (long) position_initiale, SEEK_SET) != 0)
2196: {
2197: liberation(s_etat_processus,
2198: s_objet_argument_1);
2199: liberation(s_etat_processus, s_objet_resultat);
1.59 bertrand 2200:
1.82 bertrand 2201: (*s_etat_processus).erreur_systeme =
2202: d_es_erreur_fichier;
2203: return;
2204: }
1.59 bertrand 2205: }
2206: }
2207: else
2208: {
2209: longueur_enregistrement = longueur;
2210: }
2211:
1.84 bertrand 2212: if ((device == d_vrai) && (format_degenere == d_vrai))
1.59 bertrand 2213: {
1.84 bertrand 2214: longueur_effective = longueur_enregistrement;
2215: tampon_lecture = tampon3;
1.59 bertrand 2216: }
1.84 bertrand 2217: else
2218: {
2219: if ((tampon_lecture = malloc(((size_t)
2220: longueur_enregistrement) *
2221: sizeof(unsigned char))) == NULL)
2222: {
2223: (*s_etat_processus).erreur_systeme =
2224: d_es_allocation_memoire;
2225: return;
2226: }
1.59 bertrand 2227:
1.84 bertrand 2228: longueur_effective = (integer8) fread(tampon_lecture,
2229: sizeof(unsigned char),
2230: (size_t) longueur_enregistrement,
2231: (*descripteur).descripteur_c);
2232: }
1.59 bertrand 2233:
2234: if (l_element_courant == NULL)
2235: {
2236: // Premier maillon de la liste
2237: if (((*s_objet_resultat).objet =
2238: allocation_maillon(s_etat_processus)) == NULL)
2239: {
2240: (*s_etat_processus).erreur_systeme =
2241: d_es_allocation_memoire;
2242: return;
2243: }
2244:
2245: l_element_courant = (*s_objet_resultat).objet;
2246: }
2247: else
2248: {
2249: if (((*l_element_courant).suivant =
2250: allocation_maillon(s_etat_processus)) == NULL)
2251: {
2252: (*s_etat_processus).erreur_systeme =
2253: d_es_allocation_memoire;
2254: return;
2255: }
2256:
2257: l_element_courant = (*l_element_courant).suivant;
2258: }
2259:
2260: (*l_element_courant).suivant = NULL;
2261:
2262: if (((*l_element_courant).donnee =
2263: allocation(s_etat_processus, CHN)) == NULL)
2264: {
2265: (*s_etat_processus).erreur_systeme =
2266: d_es_allocation_memoire;
2267: return;
2268: }
1.28 bertrand 2269:
1.59 bertrand 2270: if (format_degenere == d_vrai)
2271: {
1.84 bertrand 2272: if (device == d_faux)
2273: {
2274: if (((*(*l_element_courant).donnee).objet =
2275: analyse_flux(s_etat_processus, tampon_lecture,
2276: longueur_enregistrement - 1)) == NULL)
2277: {
2278: return;
2279: }
2280: }
2281: else
1.59 bertrand 2282: {
1.84 bertrand 2283: if (((*(*l_element_courant).donnee).objet =
2284: analyse_flux(s_etat_processus, tampon_lecture,
2285: longueur_enregistrement)) == NULL)
2286: {
2287: return;
2288: }
1.59 bertrand 2289: }
2290: }
2291: else
2292: {
2293: if (((*(*l_element_courant).donnee).objet =
2294: analyse_flux(s_etat_processus, tampon_lecture,
2295: longueur_enregistrement)) == NULL)
2296: {
2297: return;
2298: }
2299: }
1.28 bertrand 2300:
1.59 bertrand 2301: free(tampon_lecture);
1.28 bertrand 2302:
1.59 bertrand 2303: l_element_courant_format =
2304: (*l_element_courant_format).suivant;
1.28 bertrand 2305: }
2306:
2307: if (empilement(s_etat_processus,
2308: &((*s_etat_processus).l_base_pile),
2309: s_objet_resultat) == d_erreur)
2310: {
2311: return;
2312: }
2313: }
2314: else
2315: {
2316: liberation(s_etat_processus, s_objet_argument_1);
2317:
2318: (*s_etat_processus).erreur_execution =
2319: d_ex_erreur_type_fichier;
2320: return;
2321: }
1.1 bertrand 2322: }
2323: }
1.6 bertrand 2324: else if ((*s_objet_argument_1).type == SCK)
1.1 bertrand 2325: {
2326: /*
2327: * Vérification de l'autorisation de lecture
2328: */
2329:
1.6 bertrand 2330: if ((*((struct_socket *) (*s_objet_argument_1).objet)).protection
2331: == 'W')
1.1 bertrand 2332: {
1.6 bertrand 2333: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2334:
2335: (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
2336: return;
2337: }
2338:
2339: /*
2340: * Vérification de l'écoute de la socket si celle-ci est connectée
2341: */
2342:
1.6 bertrand 2343: if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
1.1 bertrand 2344: "STREAM") == 0) || (strcmp((*((struct_socket *)
1.6 bertrand 2345: (*s_objet_argument_1).objet)).type, "SEQUENTIAL DATAGRAM")
2346: == 0))
1.1 bertrand 2347: {
1.6 bertrand 2348: if ((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2349: .socket_en_ecoute == 'Y')
2350: {
1.6 bertrand 2351: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2352:
2353: (*s_etat_processus).erreur_execution = d_ex_socket_en_ecoute;
2354: return;
2355: }
2356: }
2357:
1.6 bertrand 2358: if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
1.1 bertrand 2359: { // Socket formatée
1.71 bertrand 2360: longueur_questure = 4096;
1.55 bertrand 2361: longueur_effective = 0;
2362: tampon_lecture = NULL;
1.1 bertrand 2363:
1.56 bertrand 2364: attente.tv_sec = 0;
2365: attente.tv_nsec = GRANULARITE_us * 1000;
2366:
1.57 bertrand 2367: trame_complete = d_faux;
2368: position_initiale = 0;
2369: position_finale = 0;
2370:
1.1 bertrand 2371: do
2372: {
1.55 bertrand 2373: presence_indicateur = d_faux;
2374:
2375: if ((tampon_lecture = realloc(tampon_lecture,
1.76 bertrand 2376: ((size_t) (longueur_effective + longueur_questure + 1))
1.55 bertrand 2377: * sizeof(unsigned char))) == NULL)
1.1 bertrand 2378: {
2379: (*s_etat_processus).erreur_systeme =
2380: d_es_allocation_memoire;
2381: return;
2382: }
2383:
1.44 bertrand 2384: # ifndef SEMAPHORES_NOMMES
2385: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
2386: # else
2387: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2388: # endif
1.1 bertrand 2389: {
2390: (*s_etat_processus).erreur_systeme = d_es_processus;
2391: return;
2392: }
2393:
1.55 bertrand 2394: if ((*((struct_socket *) (*s_objet_argument_1).objet))
2395: .domaine == PF_UNIX)
2396: {
2397: longueur_adresse = sizeof(adresse_unix);
1.57 bertrand 2398:
2399: do
2400: {
1.76 bertrand 2401: ios = (int) recvfrom((*((struct_socket *)
1.57 bertrand 2402: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2403: tampon_lecture, (size_t) (longueur_effective +
2404: longueur_questure),
1.57 bertrand 2405: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
2406: &adresse_unix, &longueur_adresse);
2407: } while((ios == -1) && (errno == EINTR));
1.55 bertrand 2408: }
2409: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
2410: .domaine == PF_INET)
2411: {
2412: longueur_adresse = sizeof(adresse_ipv4);
1.57 bertrand 2413:
2414: do
2415: {
1.76 bertrand 2416: ios = (int) recvfrom((*((struct_socket *)
1.57 bertrand 2417: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2418: tampon_lecture, (size_t) (longueur_effective +
2419: longueur_questure),
1.57 bertrand 2420: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
2421: &adresse_ipv4, &longueur_adresse);
2422: } while((ios == -1) && (errno == EINTR));
1.55 bertrand 2423: }
2424: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
2425: .domaine == PF_INET6)
2426: {
2427: # ifdef IPV6
2428: longueur_adresse = sizeof(adresse_ipv6);
1.57 bertrand 2429:
2430: do
2431: {
1.76 bertrand 2432: ios = (int) recvfrom((*((struct_socket *)
1.57 bertrand 2433: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2434: tampon_lecture, (size_t) (longueur_effective +
2435: longueur_questure),
1.57 bertrand 2436: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
2437: &adresse_ipv6, &longueur_adresse);
2438: } while((ios == -1) && (errno == EINTR));
1.55 bertrand 2439: # else
2440: if ((*s_etat_processus).langue == 'F')
2441: {
2442: printf("+++Attention : Support du protocole"
2443: " IPv6 indisponible\n");
2444: }
2445: else
2446: {
2447: printf("+++Warning : IPv6 support "
2448: "unavailable\n");
2449: }
2450:
2451: longueur_adresse = 0;
2452: longueur_effective = 0;
2453: ios = 0;
2454: # endif
2455: }
2456: else
2457: {
2458: free(tampon_lecture);
2459: liberation(s_etat_processus, s_objet_argument_1);
2460:
2461: # ifndef SEMAPHORES_NOMMES
2462: while(sem_wait(&((*s_etat_processus)
2463: .semaphore_fork)) != 0)
2464: # else
2465: while(sem_wait((*s_etat_processus)
2466: .semaphore_fork) != 0)
2467: # endif
2468: {
2469: (*s_etat_processus).erreur_systeme =
2470: d_es_processus;
2471: }
2472:
2473: (*s_etat_processus).erreur_execution =
2474: d_ex_erreur_acces_fichier;
2475: return;
2476: }
2477:
1.74 bertrand 2478: if (ios <= 0)
1.55 bertrand 2479: {
2480: nanosleep(&attente, NULL);
2481: INCR_GRANULARITE(attente.tv_nsec);
2482: }
1.56 bertrand 2483: else
2484: {
2485: attente.tv_sec = 0;
2486: attente.tv_nsec = GRANULARITE_us * 1000;
2487: }
1.55 bertrand 2488:
1.74 bertrand 2489: scrutation_injection(s_etat_processus);
2490:
1.55 bertrand 2491: if ((*s_etat_processus).var_volatile_requete_arret == -1)
2492: {
1.62 bertrand 2493: if (ios >= 0)
2494: {
1.74 bertrand 2495: longueur_effective = ios;
1.62 bertrand 2496: }
2497:
1.55 bertrand 2498: break;
2499: }
2500:
2501: // Une donnée a été reçue.
2502:
2503: if (ios >= 0)
1.1 bertrand 2504: {
1.74 bertrand 2505: longueur_effective = ios;
1.55 bertrand 2506: position_initiale = 0;
2507: presence_indicateur = d_faux;
2508:
2509: do
2510: {
2511: if (tampon_lecture[position_initiale] == '{')
2512: {
2513: presence_indicateur = d_vrai;
2514: break;
2515: }
2516:
2517: position_initiale++;
2518: } while(position_initiale < longueur_effective);
2519:
2520: if (presence_indicateur == d_vrai)
2521: {
2522: position_finale = position_initiale + 1;
2523: presence_chaine = d_faux;
2524: presence_indicateur = d_faux;
2525: niveau = 1;
2526:
2527: while(position_finale < longueur_effective)
2528: {
2529: caractere = tampon_lecture[position_finale];
2530:
2531: if (caractere == '"')
2532: {
1.59 bertrand 2533: if (position_finale > 0)
2534: {
2535: if (tampon_lecture[position_finale - 1]
2536: != '\\')
2537: {
2538: presence_chaine = (presence_chaine ==
2539: d_vrai) ? d_faux : d_vrai;
2540: }
2541: }
2542: else
2543: {
2544: presence_chaine =
2545: (presence_chaine == d_vrai)
2546: ? d_faux : d_vrai;
2547: }
1.55 bertrand 2548: }
2549: else
2550: {
2551: if (presence_chaine == d_faux)
2552: {
2553: if (caractere == '{')
2554: {
2555: niveau++;
2556: }
2557: else if (caractere == '}')
2558: {
2559: niveau--;
2560: }
2561: }
2562: }
2563:
2564: if (niveau == 0)
2565: {
2566: presence_indicateur = d_vrai;
1.57 bertrand 2567: trame_complete = d_vrai;
1.55 bertrand 2568: break;
2569: }
2570:
2571: position_finale++;
2572: }
2573: }
2574:
1.71 bertrand 2575: // On retire une trame du buffer.
1.55 bertrand 2576:
1.71 bertrand 2577: if (trame_complete == d_vrai)
1.1 bertrand 2578: {
1.71 bertrand 2579: if ((*((struct_socket *) (*s_objet_argument_1).objet))
2580: .domaine == PF_UNIX)
1.57 bertrand 2581: {
1.71 bertrand 2582: do
2583: {
2584: longueur_adresse = sizeof(adresse_unix);
2585: recvfrom((*((struct_socket *)
2586: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2587: tampon_lecture,
2588: (size_t) longueur_effective,
1.71 bertrand 2589: 0, (struct sockaddr *)
2590: &adresse_unix, &longueur_adresse);
2591: } while((ios == -1) && (errno == EINTR));
2592: }
2593: else if ((*((struct_socket *) (*s_objet_argument_1)
2594: .objet)).domaine == PF_INET)
1.57 bertrand 2595: {
1.71 bertrand 2596: do
2597: {
2598: longueur_adresse = sizeof(adresse_ipv4);
2599: recvfrom((*((struct_socket *)
2600: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2601: tampon_lecture,
2602: (size_t) longueur_effective,
1.71 bertrand 2603: 0, (struct sockaddr *)
2604: &adresse_ipv4, &longueur_adresse);
2605: } while((ios == -1) && (errno == EINTR));
1.21 bertrand 2606: }
1.71 bertrand 2607: else if ((*((struct_socket *) (*s_objet_argument_1)
2608: .objet)) .domaine == PF_INET6)
1.21 bertrand 2609: {
1.71 bertrand 2610: # ifdef IPV6
2611: do
2612: {
2613: longueur_adresse = sizeof(adresse_ipv6);
2614: recvfrom((*((struct_socket *)
2615: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2616: tampon_lecture,
2617: (size_t) longueur_effective,
1.71 bertrand 2618: 0, (struct sockaddr *)
2619: &adresse_ipv6, &longueur_adresse);
2620: } while((ios == -1) && (errno == EINTR));
2621: # else
2622: if ((*s_etat_processus).langue == 'F')
2623: {
2624: printf("+++Attention : Support du protocole"
2625: " IPv6 indisponible\n");
2626: }
2627: else
2628: {
2629: printf("+++Warning : IPv6 support "
2630: "unavailable\n");
2631: }
2632:
2633: # endif
1.21 bertrand 2634: }
1.51 bertrand 2635:
1.71 bertrand 2636: longueur_effective = ios;
1.1 bertrand 2637: }
1.71 bertrand 2638: else
2639: {
1.79 bertrand 2640: // Si on a lu toute une trame et qu'on n'a pas
2641: // réussi à en trouver la structure, on remonte
2642: // une erreur de syntaxe.
1.1 bertrand 2643:
1.79 bertrand 2644: if (longueur_effective == ios)
1.1 bertrand 2645: {
1.79 bertrand 2646: if ((*((struct_socket *) (*s_objet_argument_1)
2647: .objet)).domaine == PF_UNIX)
2648: {
2649: do
2650: {
2651: longueur_adresse = sizeof(adresse_unix);
2652: recvfrom((*((struct_socket *)
2653: (*s_objet_argument_1).objet))
2654: .socket, tampon_lecture,
2655: (size_t) longueur_effective,
2656: 0, (struct sockaddr *)
2657: &adresse_unix, &longueur_adresse);
2658: } while((ios == -1) && (errno == EINTR));
2659: }
2660: else if ((*((struct_socket *) (*s_objet_argument_1)
2661: .objet)).domaine == PF_INET)
2662: {
2663: do
2664: {
2665: longueur_adresse = sizeof(adresse_ipv4);
2666: recvfrom((*((struct_socket *)
2667: (*s_objet_argument_1).objet))
2668: .socket, tampon_lecture,
2669: (size_t) longueur_effective,
2670: 0, (struct sockaddr *)
2671: &adresse_ipv4, &longueur_adresse);
2672: } while((ios == -1) && (errno == EINTR));
2673: }
2674: else if ((*((struct_socket *) (*s_objet_argument_1)
2675: .objet)) .domaine == PF_INET6)
1.55 bertrand 2676: {
1.79 bertrand 2677: # ifdef IPV6
2678: do
1.55 bertrand 2679: {
1.79 bertrand 2680: longueur_adresse = sizeof(adresse_ipv6);
2681: recvfrom((*((struct_socket *)
2682: (*s_objet_argument_1).objet))
2683: .socket, tampon_lecture,
2684: (size_t) longueur_effective,
2685: 0, (struct sockaddr *)
2686: &adresse_ipv6, &longueur_adresse);
2687: } while((ios == -1) && (errno == EINTR));
2688: # else
2689: if ((*s_etat_processus).langue == 'F')
2690: {
2691: printf("+++Attention : Support du protocole"
2692: " IPv6 indisponible\n");
1.55 bertrand 2693: }
1.79 bertrand 2694: else
1.55 bertrand 2695: {
1.79 bertrand 2696: printf("+++Warning : IPv6 support "
2697: "unavailable\n");
2698: }
1.1 bertrand 2699:
1.79 bertrand 2700: # endif
1.55 bertrand 2701: }
1.79 bertrand 2702:
2703: liberation(s_etat_processus, s_objet_argument_1);
2704: free(tampon_lecture);
2705:
2706: (*s_etat_processus).erreur_execution = d_ex_syntaxe;
2707: return;
1.55 bertrand 2708: }
1.1 bertrand 2709: }
2710: }
2711:
1.44 bertrand 2712: # ifndef SEMAPHORES_NOMMES
2713: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
2714: # else
2715: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2716: # endif
1.1 bertrand 2717: {
1.44 bertrand 2718: if (errno == EINTR)
1.43 bertrand 2719: {
2720: (*s_etat_processus).erreur_systeme = d_es_processus;
2721: return;
2722: }
1.1 bertrand 2723: }
2724:
2725: if ((*s_etat_processus).var_volatile_requete_arret == -1)
2726: {
2727:
2728: /*
2729: * Si le père tue le processus courant grâce au signal
2730: * SIGFSTOP, on ne renvoie pas d'erreur. Ce fonctionnement
2731: * correspond à l'utilisation de STOP sur le processus
2732: * en cours. La variable longueur_effective vaut '-1'.
2733: */
2734:
2735: free(tampon_lecture);
1.6 bertrand 2736: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2737: return;
2738: }
2739:
2740: if (longueur_effective == -1)
2741: {
2742: free(tampon_lecture);
1.6 bertrand 2743: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2744:
2745: (*s_etat_processus).erreur_execution =
2746: d_ex_erreur_acces_fichier;
2747: return;
2748: }
1.57 bertrand 2749: } while(trame_complete == d_faux);
1.1 bertrand 2750:
2751: tampon_lecture[++position_finale] = d_code_fin_chaine;
2752: tampon = (*s_etat_processus).instruction_courante;
1.71 bertrand 2753: (*s_etat_processus).instruction_courante = tampon_lecture;
1.1 bertrand 2754:
2755: indicateur_48 = test_cfsf(s_etat_processus, 48);
2756: cf(s_etat_processus, 48);
2757:
2758: recherche_type(s_etat_processus);
2759:
2760: if ((*s_etat_processus).erreur_execution != d_ex)
2761: {
2762: (*s_etat_processus).instruction_courante = tampon;
2763: free(tampon_lecture);
2764:
1.57 bertrand 2765: if (indicateur_48 == d_vrai)
2766: {
2767: sf(s_etat_processus, 48);
2768: }
2769: else
2770: {
2771: cf(s_etat_processus, 48);
2772: }
2773:
2774: if ((*s_etat_processus).var_volatile_requete_arret == -1)
2775: {
2776: (*s_etat_processus).erreur_execution = d_ex;
2777: }
2778:
1.6 bertrand 2779: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2780: return;
2781: }
2782:
2783: if (indicateur_48 == d_vrai)
2784: {
2785: sf(s_etat_processus, 48);
2786: }
2787: else
2788: {
2789: cf(s_etat_processus, 48);
2790: }
2791:
2792: (*s_etat_processus).instruction_courante = tampon;
2793:
2794: /*
2795: * Création de la liste de sortie
2796: */
2797:
2798: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2799: &s_objet_type) == d_erreur)
2800: {
2801: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2802: return;
2803: }
2804:
2805: if ((s_objet_resultat = allocation(s_etat_processus, LST))
2806: == NULL)
2807: {
2808: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2809: return;
2810: }
2811:
2812: if (((*s_objet_resultat).objet =
2813: allocation_maillon(s_etat_processus)) == NULL)
2814: {
2815: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2816: return;
2817: }
2818:
2819: (*((struct_liste_chainee *) (*s_objet_resultat).objet))
2820: .donnee = s_objet_type;
2821:
2822: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet))
2823: .suivant = allocation_maillon(s_etat_processus)) == NULL)
2824: {
2825: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2826: return;
2827: }
2828:
2829: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
2830: .suivant = NULL;
2831:
2832: if ((s_objet_adresse = allocation(s_etat_processus, LST))
2833: == NULL)
2834: {
2835: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2836: return;
2837: }
2838:
2839: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
2840: .donnee = s_objet_adresse;
2841:
2842: /*
2843: * Les informations concernant la cible sont valides si
2844: * la socket est non connectée et des domaines INET ou INET6.
2845: * Dans tous les autres cas, on renvoie une liste vide.
2846: */
2847:
1.6 bertrand 2848: if (((*((struct_socket *) (*s_objet_argument_1).objet)).domaine
1.1 bertrand 2849: == PF_UNIX) || (strcmp((*((struct_socket *)
1.6 bertrand 2850: (*s_objet_argument_1).objet)).type, "STREAM") == 0) ||
2851: (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2852: .type, "SEQUENTIAL DATAGRAM") == 0))
2853: {
2854: (*s_objet_adresse).objet = NULL;
2855: }
1.6 bertrand 2856: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2857: .domaine == PF_INET)
2858: {
2859: if (((*s_objet_adresse).objet =
2860: allocation_maillon(s_etat_processus)) == NULL)
2861: {
2862: (*s_etat_processus).erreur_systeme =
2863: d_es_allocation_memoire;
2864: return;
2865: }
2866:
2867: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2868: .donnee = allocation(s_etat_processus, VIN)) == NULL)
2869: {
2870: (*s_etat_processus).erreur_systeme =
2871: d_es_allocation_memoire;
2872: return;
2873: }
2874:
2875: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
2876: (*s_objet_adresse).objet)).donnee).objet)).taille = 4;
2877:
2878: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
2879: (*s_objet_adresse).objet)).donnee).objet)).tableau =
2880: malloc(4 * sizeof(integer8))) == NULL)
2881: {
2882: (*s_etat_processus).erreur_systeme =
2883: d_es_allocation_memoire;
2884: return;
2885: }
2886:
2887: ((integer8 *) (*((struct_vecteur *)
2888: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2889: .objet)).donnee).objet)).tableau)[0] =
2890: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF;
2891: ((integer8 *) (*((struct_vecteur *)
2892: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2893: .objet)).donnee).objet)).tableau)[1] =
2894: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF;
2895: ((integer8 *) (*((struct_vecteur *)
2896: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2897: .objet)).donnee).objet)).tableau)[2] =
2898: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF;
2899: ((integer8 *) (*((struct_vecteur *)
2900: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2901: .objet)).donnee).objet)).tableau)[3] =
2902: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF;
2903:
2904: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2905: .suivant = allocation_maillon(s_etat_processus))
2906: == NULL)
2907: {
2908: (*s_etat_processus).erreur_systeme =
2909: d_es_allocation_memoire;
2910: return;
2911: }
2912:
2913: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2914: .suivant).donnee = allocation(s_etat_processus, INT))
2915: == NULL)
2916: {
2917: (*s_etat_processus).erreur_systeme =
2918: d_es_allocation_memoire;
2919: return;
2920: }
2921:
2922: (*((integer8 *) (*(*(*((struct_liste_chainee *)
1.6 bertrand 2923: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
1.1 bertrand 2924: (integer8) ntohs(adresse_ipv4.sin_port);
2925:
2926: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2927: .suivant).suivant = NULL;
2928: }
1.6 bertrand 2929: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2930: .domaine == PF_INET6)
2931: {
1.19 bertrand 2932: # ifdef IPV6
1.1 bertrand 2933: if (((*s_objet_adresse).objet =
2934: allocation_maillon(s_etat_processus)) == NULL)
2935: {
2936: (*s_etat_processus).erreur_systeme =
2937: d_es_allocation_memoire;
2938: return;
2939: }
2940:
2941: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2942: .donnee = allocation(s_etat_processus, VIN)) == NULL)
2943: {
2944: (*s_etat_processus).erreur_systeme =
2945: d_es_allocation_memoire;
2946: return;
2947: }
2948:
2949: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
2950: (*s_objet_adresse).objet)).donnee).objet)).taille = 16;
2951:
2952: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
2953: (*s_objet_adresse).objet)).donnee).objet)).tableau =
2954: malloc(16 * sizeof(integer8))) == NULL)
2955: {
2956: (*s_etat_processus).erreur_systeme =
2957: d_es_allocation_memoire;
2958: return;
2959: }
2960:
2961: for(i = 0; i < 16; i++)
2962: {
2963: ((integer8 *) (*((struct_vecteur *)
2964: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2965: .objet)).donnee).objet)).tableau)[0] =
2966: adresse_ipv6.sin6_addr.s6_addr[i];
2967: }
2968:
2969: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2970: .suivant = allocation_maillon(s_etat_processus))
2971: == NULL)
2972: {
2973: (*s_etat_processus).erreur_systeme =
2974: d_es_allocation_memoire;
2975: return;
2976: }
2977:
2978: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2979: .suivant).donnee = allocation(s_etat_processus, INT))
2980: == NULL)
2981: {
2982: (*s_etat_processus).erreur_systeme =
2983: d_es_allocation_memoire;
2984: return;
2985: }
2986:
2987: (*((integer8 *) (*(*(*((struct_liste_chainee *)
1.6 bertrand 2988: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
1.1 bertrand 2989: (integer8) ntohs(adresse_ipv6.sin6_port);
2990:
2991: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2992: .suivant).suivant = NULL;
1.19 bertrand 2993: # else
1.21 bertrand 2994: if ((*s_etat_processus).langue == 'F')
2995: {
2996: printf("+++Attention : Support du protocole"
1.22 bertrand 2997: " IPv6 indisponible\n");
1.21 bertrand 2998: }
2999: else
3000: {
1.23 bertrand 3001: printf("+++Warning : IPv6 support "
1.21 bertrand 3002: "unavailable\n");
3003: }
1.19 bertrand 3004: # endif
1.1 bertrand 3005: }
3006: else
3007: {
3008: longueur_adresse = 0;
3009: recvfrom((*((struct_socket *)
1.6 bertrand 3010: (*s_objet_argument_1).objet)).socket, tampon_lecture,
1.76 bertrand 3011: (size_t) position_finale, MSG_DONTWAIT,
1.1 bertrand 3012: NULL, &longueur_adresse);
3013: }
3014:
3015: free(tampon_lecture);
3016:
3017: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3018: s_objet_resultat) == d_erreur)
3019: {
3020: return;
3021: }
3022: }
1.28 bertrand 3023: else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
3024: == 'Y')
1.73 bertrand 3025: { // socket non formatée
3026: longueur_questure = 4096;
3027: longueur_effective = 0;
3028: tampon_lecture = NULL;
3029:
3030: attente.tv_sec = 0;
3031: attente.tv_nsec = GRANULARITE_us * 1000;
3032:
3033: trame_complete = d_faux;
3034: position_initiale = 0;
3035: position_finale = 0;
3036:
3037: do
3038: {
3039: presence_indicateur = d_faux;
3040:
3041: if ((tampon_lecture = realloc(tampon_lecture,
1.76 bertrand 3042: ((size_t) (longueur_effective + longueur_questure) + 1)
1.73 bertrand 3043: * sizeof(unsigned char))) == NULL)
3044: {
3045: (*s_etat_processus).erreur_systeme =
3046: d_es_allocation_memoire;
3047: return;
3048: }
3049:
3050: # ifndef SEMAPHORES_NOMMES
3051: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3052: # else
3053: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3054: # endif
3055: {
3056: (*s_etat_processus).erreur_systeme = d_es_processus;
3057: return;
3058: }
3059:
3060: if ((*((struct_socket *) (*s_objet_argument_1).objet))
3061: .domaine == PF_UNIX)
3062: {
3063: longueur_adresse = sizeof(adresse_unix);
3064:
3065: do
3066: {
1.76 bertrand 3067: ios = (int) recvfrom((*((struct_socket *)
1.73 bertrand 3068: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3069: tampon_lecture, (size_t)
3070: (longueur_effective + longueur_questure),
1.73 bertrand 3071: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3072: &adresse_unix, &longueur_adresse);
3073: } while((ios == -1) && (errno == EINTR));
3074: }
3075: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3076: .domaine == PF_INET)
3077: {
3078: longueur_adresse = sizeof(adresse_ipv4);
3079:
3080: do
3081: {
1.76 bertrand 3082: ios = (int) recvfrom((*((struct_socket *)
1.73 bertrand 3083: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3084: tampon_lecture, (size_t)
3085: (longueur_effective + longueur_questure),
1.73 bertrand 3086: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3087: &adresse_ipv4, &longueur_adresse);
3088: } while((ios == -1) && (errno == EINTR));
3089: }
3090: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3091: .domaine == PF_INET6)
3092: {
3093: # ifdef IPV6
3094: longueur_adresse = sizeof(adresse_ipv6);
3095:
3096: do
3097: {
1.76 bertrand 3098: ios = (int) recvfrom((*((struct_socket *)
1.73 bertrand 3099: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3100: tampon_lecture, (size_t)
3101: (longueur_effective + longueur_questure),
1.73 bertrand 3102: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3103: &adresse_ipv6, &longueur_adresse);
3104: } while((ios == -1) && (errno == EINTR));
3105: # else
3106: if ((*s_etat_processus).langue == 'F')
3107: {
3108: printf("+++Attention : Support du protocole"
3109: " IPv6 indisponible\n");
3110: }
3111: else
3112: {
3113: printf("+++Warning : IPv6 support "
3114: "unavailable\n");
3115: }
3116:
3117: longueur_adresse = 0;
3118: longueur_effective = 0;
3119: ios = 0;
3120: # endif
3121: }
3122: else
3123: {
3124: free(tampon_lecture);
3125: liberation(s_etat_processus, s_objet_argument_1);
3126:
3127: # ifndef SEMAPHORES_NOMMES
3128: while(sem_wait(&((*s_etat_processus)
3129: .semaphore_fork)) != 0)
3130: # else
3131: while(sem_wait((*s_etat_processus)
3132: .semaphore_fork) != 0)
3133: # endif
3134: {
3135: (*s_etat_processus).erreur_systeme =
3136: d_es_processus;
3137: }
3138:
3139: (*s_etat_processus).erreur_execution =
3140: d_ex_erreur_acces_fichier;
3141: return;
3142: }
3143:
1.74 bertrand 3144: if (ios <= 0)
1.73 bertrand 3145: {
3146: nanosleep(&attente, NULL);
3147: INCR_GRANULARITE(attente.tv_nsec);
3148: }
3149: else
3150: {
3151: attente.tv_sec = 0;
3152: attente.tv_nsec = GRANULARITE_us * 1000;
3153: }
3154:
1.74 bertrand 3155: scrutation_injection(s_etat_processus);
3156:
1.73 bertrand 3157: if ((*s_etat_processus).var_volatile_requete_arret == -1)
3158: {
3159: if (ios >= 0)
3160: {
3161: longueur_effective += ios;
3162: }
3163:
3164: break;
3165: }
3166:
3167: // Une donnée a été reçue.
3168:
1.74 bertrand 3169: if (ios == (longueur_effective + longueur_questure))
1.73 bertrand 3170: {
1.74 bertrand 3171: longueur_effective = ios;
1.73 bertrand 3172: position_initiale = 0;
3173: presence_indicateur = d_faux;
1.74 bertrand 3174: }
3175: else if (ios > 0)
3176: {
3177: // On retire une trame du buffer.
1.73 bertrand 3178:
1.74 bertrand 3179: if ((*((struct_socket *) (*s_objet_argument_1).objet))
3180: .domaine == PF_UNIX)
1.73 bertrand 3181: {
1.74 bertrand 3182: do
1.73 bertrand 3183: {
1.74 bertrand 3184: longueur_adresse = sizeof(adresse_unix);
3185: recvfrom((*((struct_socket *)
3186: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3187: tampon_lecture, (size_t) longueur_effective,
1.74 bertrand 3188: 0, (struct sockaddr *)
3189: &adresse_unix, &longueur_adresse);
3190: } while((ios == -1) && (errno == EINTR));
3191: }
3192: else if ((*((struct_socket *) (*s_objet_argument_1)
3193: .objet)).domaine == PF_INET)
1.73 bertrand 3194: {
1.74 bertrand 3195: do
1.73 bertrand 3196: {
1.74 bertrand 3197: longueur_adresse = sizeof(adresse_ipv4);
3198: recvfrom((*((struct_socket *)
3199: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3200: tampon_lecture, (size_t) longueur_effective,
1.74 bertrand 3201: 0, (struct sockaddr *)
3202: &adresse_ipv4, &longueur_adresse);
3203: } while((ios == -1) && (errno == EINTR));
1.73 bertrand 3204: }
1.74 bertrand 3205: else if ((*((struct_socket *) (*s_objet_argument_1)
3206: .objet)) .domaine == PF_INET6)
1.73 bertrand 3207: {
1.74 bertrand 3208: # ifdef IPV6
3209: do
1.73 bertrand 3210: {
1.74 bertrand 3211: longueur_adresse = sizeof(adresse_ipv6);
3212: recvfrom((*((struct_socket *)
3213: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3214: tampon_lecture, (size_t) longueur_effective,
1.74 bertrand 3215: 0, (struct sockaddr *)
3216: &adresse_ipv6, &longueur_adresse);
3217: } while((ios == -1) && (errno == EINTR));
3218: # else
3219: if ((*s_etat_processus).langue == 'F')
1.73 bertrand 3220: {
1.74 bertrand 3221: printf("+++Attention : Support du protocole"
3222: " IPv6 indisponible\n");
1.73 bertrand 3223: }
1.74 bertrand 3224: else
1.73 bertrand 3225: {
1.74 bertrand 3226: printf("+++Warning : IPv6 support "
3227: "unavailable\n");
1.73 bertrand 3228: }
1.74 bertrand 3229: # endif
1.73 bertrand 3230: }
3231:
1.74 bertrand 3232: longueur_effective = ios;
3233: trame_complete = d_vrai;
1.73 bertrand 3234: }
3235:
3236: # ifndef SEMAPHORES_NOMMES
3237: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3238: # else
3239: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3240: # endif
3241: {
3242: if (errno == EINTR)
3243: {
3244: (*s_etat_processus).erreur_systeme = d_es_processus;
3245: return;
3246: }
3247: }
3248:
3249: if ((*s_etat_processus).var_volatile_requete_arret == -1)
3250: {
3251:
3252: /*
3253: * Si le père tue le processus courant grâce au signal
3254: * SIGFSTOP, on ne renvoie pas d'erreur. Ce fonctionnement
3255: * correspond à l'utilisation de STOP sur le processus
3256: * en cours. La variable longueur_effective vaut '-1'.
3257: */
3258:
3259: free(tampon_lecture);
3260: liberation(s_etat_processus, s_objet_argument_1);
3261: return;
3262: }
3263:
3264: if (longueur_effective == -1)
3265: {
3266: free(tampon_lecture);
3267: liberation(s_etat_processus, s_objet_argument_1);
3268:
3269: (*s_etat_processus).erreur_execution =
3270: d_ex_erreur_acces_fichier;
3271: return;
3272: }
3273: } while(trame_complete == d_faux);
3274:
1.74 bertrand 3275: /*
3276: * Création de la liste de sortie
3277: */
1.73 bertrand 3278:
1.74 bertrand 3279: ptr = tampon_lecture;
1.73 bertrand 3280:
1.74 bertrand 3281: if ((s_objet_type = lecture_fichier_non_formate(s_etat_processus,
3282: &ptr, longueur_effective, d_faux)) == NULL)
1.73 bertrand 3283: {
3284: free(tampon_lecture);
3285:
1.74 bertrand 3286: (*s_etat_processus).erreur_execution = d_ex_syntaxe;
1.73 bertrand 3287: return;
3288: }
3289:
3290: if ((s_objet_resultat = allocation(s_etat_processus, LST))
3291: == NULL)
3292: {
3293: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3294: return;
3295: }
3296:
3297: if (((*s_objet_resultat).objet =
3298: allocation_maillon(s_etat_processus)) == NULL)
3299: {
3300: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3301: return;
3302: }
3303:
3304: (*((struct_liste_chainee *) (*s_objet_resultat).objet))
3305: .donnee = s_objet_type;
3306:
3307: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet))
3308: .suivant = allocation_maillon(s_etat_processus)) == NULL)
3309: {
3310: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3311: return;
3312: }
3313:
3314: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3315: .suivant = NULL;
3316:
3317: if ((s_objet_adresse = allocation(s_etat_processus, LST))
3318: == NULL)
3319: {
3320: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3321: return;
3322: }
3323:
3324: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3325: .donnee = s_objet_adresse;
3326:
3327: /*
3328: * Les informations concernant la cible sont valides si
3329: * la socket est non connectée et des domaines INET ou INET6.
3330: * Dans tous les autres cas, on renvoie une liste vide.
3331: */
3332:
3333: if (((*((struct_socket *) (*s_objet_argument_1).objet)).domaine
3334: == PF_UNIX) || (strcmp((*((struct_socket *)
3335: (*s_objet_argument_1).objet)).type, "STREAM") == 0) ||
3336: (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
3337: .type, "SEQUENTIAL DATAGRAM") == 0))
3338: {
3339: (*s_objet_adresse).objet = NULL;
3340: }
3341: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3342: .domaine == PF_INET)
3343: {
3344: if (((*s_objet_adresse).objet =
3345: allocation_maillon(s_etat_processus)) == NULL)
3346: {
3347: (*s_etat_processus).erreur_systeme =
3348: d_es_allocation_memoire;
3349: return;
3350: }
3351:
3352: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3353: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3354: {
3355: (*s_etat_processus).erreur_systeme =
3356: d_es_allocation_memoire;
3357: return;
3358: }
3359:
3360: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3361: (*s_objet_adresse).objet)).donnee).objet)).taille = 4;
3362:
3363: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3364: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3365: malloc(4 * sizeof(integer8))) == NULL)
3366: {
3367: (*s_etat_processus).erreur_systeme =
3368: d_es_allocation_memoire;
3369: return;
3370: }
3371:
3372: ((integer8 *) (*((struct_vecteur *)
3373: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3374: .objet)).donnee).objet)).tableau)[0] =
3375: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF;
3376: ((integer8 *) (*((struct_vecteur *)
3377: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3378: .objet)).donnee).objet)).tableau)[1] =
3379: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF;
3380: ((integer8 *) (*((struct_vecteur *)
3381: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3382: .objet)).donnee).objet)).tableau)[2] =
3383: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF;
3384: ((integer8 *) (*((struct_vecteur *)
3385: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3386: .objet)).donnee).objet)).tableau)[3] =
3387: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF;
3388:
3389: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3390: .suivant = allocation_maillon(s_etat_processus))
3391: == NULL)
3392: {
3393: (*s_etat_processus).erreur_systeme =
3394: d_es_allocation_memoire;
3395: return;
3396: }
3397:
3398: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3399: .suivant).donnee = allocation(s_etat_processus, INT))
3400: == NULL)
3401: {
3402: (*s_etat_processus).erreur_systeme =
3403: d_es_allocation_memoire;
3404: return;
3405: }
3406:
3407: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3408: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3409: (integer8) ntohs(adresse_ipv4.sin_port);
3410:
3411: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3412: .suivant).suivant = NULL;
3413: }
3414: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3415: .domaine == PF_INET6)
3416: {
3417: # ifdef IPV6
3418: if (((*s_objet_adresse).objet =
3419: allocation_maillon(s_etat_processus)) == NULL)
3420: {
3421: (*s_etat_processus).erreur_systeme =
3422: d_es_allocation_memoire;
3423: return;
3424: }
3425:
3426: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3427: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3428: {
3429: (*s_etat_processus).erreur_systeme =
3430: d_es_allocation_memoire;
3431: return;
3432: }
3433:
3434: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3435: (*s_objet_adresse).objet)).donnee).objet)).taille = 16;
3436:
3437: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3438: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3439: malloc(16 * sizeof(integer8))) == NULL)
3440: {
3441: (*s_etat_processus).erreur_systeme =
3442: d_es_allocation_memoire;
3443: return;
3444: }
3445:
3446: for(i = 0; i < 16; i++)
3447: {
3448: ((integer8 *) (*((struct_vecteur *)
3449: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3450: .objet)).donnee).objet)).tableau)[0] =
3451: adresse_ipv6.sin6_addr.s6_addr[i];
3452: }
3453:
3454: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3455: .suivant = allocation_maillon(s_etat_processus))
3456: == NULL)
3457: {
3458: (*s_etat_processus).erreur_systeme =
3459: d_es_allocation_memoire;
3460: return;
3461: }
3462:
3463: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3464: .suivant).donnee = allocation(s_etat_processus, INT))
3465: == NULL)
3466: {
3467: (*s_etat_processus).erreur_systeme =
3468: d_es_allocation_memoire;
3469: return;
3470: }
3471:
3472: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3473: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3474: (integer8) ntohs(adresse_ipv6.sin6_port);
3475:
3476: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3477: .suivant).suivant = NULL;
3478: # else
3479: if ((*s_etat_processus).langue == 'F')
3480: {
3481: printf("+++Attention : Support du protocole"
3482: " IPv6 indisponible\n");
3483: }
3484: else
3485: {
3486: printf("+++Warning : IPv6 support "
3487: "unavailable\n");
3488: }
3489: # endif
3490: }
3491: else
3492: {
3493: longueur_adresse = 0;
3494: recvfrom((*((struct_socket *)
3495: (*s_objet_argument_1).objet)).socket, tampon_lecture,
1.76 bertrand 3496: (size_t) position_finale, MSG_DONTWAIT,
1.73 bertrand 3497: NULL, &longueur_adresse);
3498: }
3499:
3500: free(tampon_lecture);
3501:
3502: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3503: s_objet_resultat) == d_erreur)
3504: {
3505: return;
3506: }
1.28 bertrand 3507: }
1.1 bertrand 3508: else
1.28 bertrand 3509: { // FLOW
1.73 bertrand 3510: #if 0
1.28 bertrand 3511: longueur_questure = 256;
3512:
3513: do
3514: {
3515: if ((tampon_lecture = malloc((longueur_questure + 1) *
3516: sizeof(unsigned char))) == NULL)
3517: {
3518: (*s_etat_processus).erreur_systeme =
3519: d_es_allocation_memoire;
3520: return;
3521: }
3522:
1.44 bertrand 3523: # ifndef SEMAPHORES_NOMMES
3524: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3525: # else
3526: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3527: # endif
1.28 bertrand 3528: {
3529: (*s_etat_processus).erreur_systeme = d_es_processus;
3530: return;
3531: }
3532:
1.30 bertrand 3533: attente.tv_sec = 0;
3534: attente.tv_nsec = GRANULARITE_us * 1000;
3535:
1.28 bertrand 3536: for(;;)
3537: {
3538: if ((*((struct_socket *) (*s_objet_argument_1).objet))
3539: .domaine == PF_UNIX)
3540: {
3541: longueur_adresse = sizeof(adresse_unix);
3542: longueur_effective = recvfrom((*((struct_socket *)
3543: (*s_objet_argument_1).objet)).socket,
3544: tampon_lecture, longueur_questure,
3545: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3546: &adresse_unix, &longueur_adresse);
3547: }
3548: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3549: .domaine == PF_INET)
3550: {
3551: longueur_adresse = sizeof(adresse_ipv4);
3552: longueur_effective = recvfrom((*((struct_socket *)
3553: (*s_objet_argument_1).objet)).socket,
3554: tampon_lecture, longueur_questure,
3555: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3556: &adresse_ipv4, &longueur_adresse);
3557: }
3558: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3559: .domaine == PF_INET6)
3560: {
3561: # ifdef IPV6
3562: longueur_adresse = sizeof(adresse_ipv6);
3563: longueur_effective = recvfrom((*((struct_socket *)
3564: (*s_objet_argument_1).objet)).socket,
3565: tampon_lecture, longueur_questure,
3566: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3567: &adresse_ipv6, &longueur_adresse);
3568: # else
3569: if ((*s_etat_processus).langue == 'F')
3570: {
3571: printf("+++Attention : Support du protocole"
3572: " IPv6 indisponible\n");
3573: }
3574: else
3575: {
3576: printf("+++Warning : IPv6 support "
3577: "unavailable\n");
3578: }
1.51 bertrand 3579:
3580: longueur_adresse = 0;
3581: longueur_effective = 0;
1.28 bertrand 3582: # endif
3583: }
3584: else
3585: {
3586: free(tampon_lecture);
3587: liberation(s_etat_processus, s_objet_argument_1);
3588:
1.44 bertrand 3589: # ifndef SEMAPHORES_NOMMES
3590: while(sem_wait(&((*s_etat_processus)
3591: .semaphore_fork)) != 0)
3592: # else
3593: while(sem_wait((*s_etat_processus)
3594: .semaphore_fork) != 0)
3595: # endif
1.28 bertrand 3596: {
1.43 bertrand 3597: if (errno != EINTR)
3598: {
3599: (*s_etat_processus).erreur_systeme =
3600: d_es_processus;
3601: return;
3602: }
1.28 bertrand 3603: }
3604:
3605: (*s_etat_processus).erreur_execution =
3606: d_ex_erreur_acces_fichier;
3607: return;
3608: }
3609:
3610: if (longueur_effective < 0)
3611: {
3612: nanosleep(&attente, NULL);
1.30 bertrand 3613: INCR_GRANULARITE(attente.tv_nsec);
1.28 bertrand 3614: scrutation_injection(s_etat_processus);
3615: }
3616:
3617: if (((*s_etat_processus).var_volatile_requete_arret == -1)
3618: || (longueur_effective >= 0))
3619: {
3620: break;
3621: }
3622: }
3623:
1.44 bertrand 3624: # ifndef SEMAPHORES_NOMMES
3625: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3626: # else
3627: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3628: # endif
1.28 bertrand 3629: {
1.43 bertrand 3630: if (errno != EINTR)
3631: {
3632: (*s_etat_processus).erreur_systeme = d_es_processus;
3633: return;
3634: }
1.28 bertrand 3635: }
3636:
3637: if ((*s_etat_processus).var_volatile_requete_arret == -1)
3638: {
3639:
3640: /*
3641: * Si le père tue le processus courant grâce au signal
3642: * SIGFSTOP, on ne renvoie pas d'erreur. Ce fonctionnement
3643: * correspond à l'utilisation de STOP sur le processus
3644: * en cours. La variable longueur_effective vaut '-1'.
3645: */
3646:
3647: free(tampon_lecture);
3648: liberation(s_etat_processus, s_objet_argument_1);
3649: return;
3650: }
3651:
3652: if (longueur_effective == -1)
3653: {
3654: free(tampon_lecture);
3655: liberation(s_etat_processus, s_objet_argument_1);
3656:
3657: (*s_etat_processus).erreur_execution =
3658: d_ex_erreur_acces_fichier;
3659: return;
3660: }
3661:
3662: if (longueur_effective == longueur_questure)
3663: {
3664: free(tampon_lecture);
3665: longueur_questure *= 2;
3666: }
3667: } while(longueur_effective == longueur_questure);
3668:
3669: longueur_enregistrement = 1;
3670:
3671: for(i = 0; i < longueur_effective; i++)
3672: {
3673: if (isprint(tampon_lecture[i]) != 0)
3674: {
3675: longueur_enregistrement += 4;
3676: }
3677: else
3678: {
3679: longueur_enregistrement++;
3680: }
3681: }
3682:
3683: /*
3684: * Création de la liste de sortie
3685: */
3686:
3687: if ((s_objet_type = allocation(s_etat_processus, CHN)) == NULL)
3688: {
3689: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3690: return;
3691: }
3692:
3693: if (((*s_objet_type).objet = malloc(longueur_enregistrement *
3694: sizeof(unsigned char))) == NULL)
3695: {
3696: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3697: return;
3698: }
3699:
3700: ptr = (*s_objet_type).objet;
3701:
3702: for(i = 0; i < longueur_effective; i++)
3703: {
3704: if (isprint(tampon_lecture[i]) != 0)
3705: {
3706: (*ptr) = tampon_lecture[i];
3707: ptr++;
3708: }
3709: else
3710: {
3711: (*ptr) = '\\';
3712: ptr++;
3713: (*ptr) = 'x';
3714: ptr++;
3715: sprintf(ptr, "%02X", tampon_lecture[i]);
3716: ptr += 2;
3717: }
3718: }
3719:
3720: (*ptr) = d_code_fin_chaine;
3721:
3722: if ((s_objet_resultat = allocation(s_etat_processus, LST))
3723: == NULL)
3724: {
3725: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3726: return;
3727: }
3728:
3729: if (((*s_objet_resultat).objet =
3730: allocation_maillon(s_etat_processus)) == NULL)
3731: {
3732: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3733: return;
3734: }
3735:
3736: (*((struct_liste_chainee *) (*s_objet_resultat).objet))
3737: .donnee = s_objet_type;
3738:
3739: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet))
3740: .suivant = allocation_maillon(s_etat_processus)) == NULL)
3741: {
3742: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3743: return;
3744: }
3745:
3746: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3747: .suivant = NULL;
3748:
3749: if ((s_objet_adresse = allocation(s_etat_processus, LST))
3750: == NULL)
3751: {
3752: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3753: return;
3754: }
3755:
3756: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3757: .donnee = s_objet_adresse;
3758:
3759: /*
3760: * Les informations concernant la cible sont valides si
1.30 bertrand 3761: * la socket est non connectée et que les domaines sont
3762: * INET ou INET6.
1.28 bertrand 3763: * Dans tous les autres cas, on renvoie une liste vide.
3764: */
3765:
3766: if (((*((struct_socket *) (*s_objet_argument_1).objet)).domaine
3767: == PF_UNIX) || (strcmp((*((struct_socket *)
3768: (*s_objet_argument_1).objet)).type, "STREAM") == 0) ||
3769: (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
3770: .type, "SEQUENTIAL DATAGRAM") == 0))
3771: {
1.30 bertrand 3772: // POSITION_FINALE peut être utilisée sans être initialisée !
3773: // virer position_finale pour longueur_effective
1.28 bertrand 3774: longueur_adresse = 0;
3775: recvfrom((*((struct_socket *)
3776: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3777: position_finale, MSG_DONTWAIT,
3778: NULL, &longueur_adresse);
3779:
3780: (*s_objet_adresse).objet = NULL;
3781: }
3782: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3783: .domaine == PF_INET)
3784: {
3785: longueur_adresse = sizeof(adresse_ipv4);
3786: recvfrom((*((struct_socket *)
3787: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3788: position_finale, MSG_DONTWAIT,
3789: (struct sockaddr *) &adresse_ipv4, &longueur_adresse);
3790:
3791: if (((*s_objet_adresse).objet =
3792: allocation_maillon(s_etat_processus)) == NULL)
3793: {
3794: (*s_etat_processus).erreur_systeme =
3795: d_es_allocation_memoire;
3796: return;
3797: }
3798:
3799: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3800: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3801: {
3802: (*s_etat_processus).erreur_systeme =
3803: d_es_allocation_memoire;
3804: return;
3805: }
3806:
3807: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3808: (*s_objet_adresse).objet)).donnee).objet)).taille = 4;
3809:
3810: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3811: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3812: malloc(4 * sizeof(integer8))) == NULL)
3813: {
3814: (*s_etat_processus).erreur_systeme =
3815: d_es_allocation_memoire;
3816: return;
3817: }
3818:
3819: ((integer8 *) (*((struct_vecteur *)
3820: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3821: .objet)).donnee).objet)).tableau)[0] =
3822: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF;
3823: ((integer8 *) (*((struct_vecteur *)
3824: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3825: .objet)).donnee).objet)).tableau)[1] =
3826: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF;
3827: ((integer8 *) (*((struct_vecteur *)
3828: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3829: .objet)).donnee).objet)).tableau)[2] =
3830: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF;
3831: ((integer8 *) (*((struct_vecteur *)
3832: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3833: .objet)).donnee).objet)).tableau)[3] =
3834: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF;
3835:
3836: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3837: .suivant = allocation_maillon(s_etat_processus))
3838: == NULL)
3839: {
3840: (*s_etat_processus).erreur_systeme =
3841: d_es_allocation_memoire;
3842: return;
3843: }
3844:
3845: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3846: .suivant).donnee = allocation(s_etat_processus, INT))
3847: == NULL)
3848: {
3849: (*s_etat_processus).erreur_systeme =
3850: d_es_allocation_memoire;
3851: return;
3852: }
3853:
3854: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3855: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3856: (integer8) ntohs(adresse_ipv4.sin_port);
3857:
3858: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3859: .suivant).suivant = NULL;
3860: }
3861: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3862: .domaine == PF_INET6)
3863: {
3864: # ifdef IPV6
3865: longueur_adresse = sizeof(adresse_ipv6);
3866: recvfrom((*((struct_socket *)
3867: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3868: position_finale, MSG_DONTWAIT,
3869: (struct sockaddr *) &adresse_ipv6, &longueur_adresse);
3870:
3871: if (((*s_objet_adresse).objet =
3872: allocation_maillon(s_etat_processus)) == NULL)
3873: {
3874: (*s_etat_processus).erreur_systeme =
3875: d_es_allocation_memoire;
3876: return;
3877: }
3878:
3879: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3880: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3881: {
3882: (*s_etat_processus).erreur_systeme =
3883: d_es_allocation_memoire;
3884: return;
3885: }
3886:
3887: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3888: (*s_objet_adresse).objet)).donnee).objet)).taille = 16;
3889:
3890: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3891: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3892: malloc(16 * sizeof(integer8))) == NULL)
3893: {
3894: (*s_etat_processus).erreur_systeme =
3895: d_es_allocation_memoire;
3896: return;
3897: }
3898:
3899: for(i = 0; i < 16; i++)
3900: {
3901: ((integer8 *) (*((struct_vecteur *)
3902: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3903: .objet)).donnee).objet)).tableau)[0] =
3904: adresse_ipv6.sin6_addr.s6_addr[i];
3905: }
3906:
3907: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3908: .suivant = allocation_maillon(s_etat_processus))
3909: == NULL)
3910: {
3911: (*s_etat_processus).erreur_systeme =
3912: d_es_allocation_memoire;
3913: return;
3914: }
3915:
3916: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3917: .suivant).donnee = allocation(s_etat_processus, INT))
3918: == NULL)
3919: {
3920: (*s_etat_processus).erreur_systeme =
3921: d_es_allocation_memoire;
3922: return;
3923: }
3924:
3925: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3926: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3927: (integer8) ntohs(adresse_ipv6.sin6_port);
3928:
3929: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3930: .suivant).suivant = NULL;
3931: # else
3932: if ((*s_etat_processus).langue == 'F')
3933: {
3934: printf("+++Attention : Support du protocole"
3935: " IPv6 indisponible\n");
3936: }
3937: else
3938: {
3939: printf("+++Warning : IPv6 support "
3940: "unavailable\n");
3941: }
3942: # endif
3943: }
3944: else
3945: {
3946: longueur_adresse = 0;
3947: recvfrom((*((struct_socket *)
3948: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3949: position_finale, MSG_DONTWAIT,
3950: NULL, &longueur_adresse);
3951: }
3952:
3953: free(tampon_lecture);
3954:
3955: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3956: s_objet_resultat) == d_erreur)
3957: {
3958: return;
3959: }
1.73 bertrand 3960: #endif
1.1 bertrand 3961: }
3962: }
3963: else
3964: {
3965: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3966: return;
3967: }
3968:
1.6 bertrand 3969: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 3970:
3971: return;
3972: }
3973:
3974: // vim: ts=4