![]() ![]() | ![]() |
1.1 bertrand 1: /*
2: ================================================================================
1.100 ! bertrand 3: RPL/2 (R) version 4.1.26
1.98 bertrand 4: Copyright (C) 1989-2016 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:
1.90 bertrand 1278: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 1279: recherche_type(s_etat_processus);
1.5 bertrand 1280: free((*s_etat_processus).instruction_courante);
1.1 bertrand 1281:
1282: if ((*s_etat_processus).erreur_execution != d_ex)
1283: {
1.6 bertrand 1284: if (indicateur_48 == d_vrai)
1285: {
1286: sf(s_etat_processus, 48);
1287: }
1288: else
1289: {
1290: cf(s_etat_processus, 48);
1291: }
1292:
1.1 bertrand 1293: (*s_etat_processus).instruction_courante = tampon;
1294: free(tampon_lecture);
1295:
1.6 bertrand 1296: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 1297: return;
1298: }
1299:
1300: if (indicateur_48 == d_vrai)
1301: {
1302: sf(s_etat_processus, 48);
1303: }
1304: else
1305: {
1306: cf(s_etat_processus, 48);
1307: }
1308:
1309: (*s_etat_processus).instruction_courante = tampon;
1310: free(tampon_lecture);
1311: }
1.6 bertrand 1312: else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1.1 bertrand 1313: == 'D')
1314: {
1.6 bertrand 1315: BUG(((*descripteur).type != 'S'), uprintf("Bad filtype !\n"));
1316:
1317: if (depilement(s_etat_processus, &((*s_etat_processus)
1318: .l_base_pile), &s_objet_argument_2) == d_erreur)
1319: {
1320: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1321: return;
1322: }
1323:
1324: if ((*s_objet_argument_2).type != INT)
1325: {
1326: liberation(s_etat_processus, s_objet_argument_1);
1327: liberation(s_etat_processus, s_objet_argument_2);
1328:
1329: (*s_etat_processus).erreur_execution =
1330: d_ex_erreur_type_argument;
1331: return;
1332: }
1333:
1.93 bertrand 1334: if (alsprintf(s_etat_processus, &commande,
1335: "select data from data where id = %lld",
1336: (*((integer8 *) (*s_objet_argument_2).objet))) < 0)
1.6 bertrand 1337: {
1338: (*s_etat_processus).erreur_systeme =
1339: d_es_allocation_memoire;
1340: return;
1341: }
1342:
1343: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1344: commande, (int) strlen(commande), &ppStmt, &queue)
1.6 bertrand 1345: != SQLITE_OK)
1346: {
1347: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1348: return;
1349: }
1.68 bertrand 1350:
1351: attente.tv_sec = 0;
1352: attente.tv_nsec = GRANULARITE_us * 1000;
1353:
1354: do
1.6 bertrand 1355: {
1.68 bertrand 1356: ios = sqlite3_step(ppStmt);
1.6 bertrand 1357:
1.68 bertrand 1358: switch(ios)
1.6 bertrand 1359: {
1.68 bertrand 1360: case SQLITE_ROW:
1.6 bertrand 1361: {
1.68 bertrand 1362: // Résultat attendu
1363: break;
1.6 bertrand 1364: }
1365:
1.68 bertrand 1366: case SQLITE_DONE:
1367: {
1368: // Aucun enregistrement
1369: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1370: {
1371: (*s_etat_processus).erreur_systeme =
1372: d_es_erreur_fichier;
1373: return;
1374: }
1375:
1376: free(commande);
1.6 bertrand 1377:
1.68 bertrand 1378: liberation(s_etat_processus, s_objet_argument_1);
1379: liberation(s_etat_processus, s_objet_argument_2);
1380:
1381: (*s_etat_processus).erreur_execution =
1382: d_ex_enregistrement_inexistant;
1383: return;
1384: }
1.6 bertrand 1385:
1.68 bertrand 1386: case SQLITE_BUSY:
1387: case SQLITE_LOCKED:
1388: {
1389: nanosleep(&attente, NULL);
1390: INCR_GRANULARITE(attente.tv_nsec);
1391: break;
1392: }
1.6 bertrand 1393:
1.68 bertrand 1394: default:
1395: {
1396: (*s_etat_processus).erreur_systeme =
1397: d_es_erreur_fichier;
1398: return;
1399: }
1.6 bertrand 1400: }
1.68 bertrand 1401: } while(ios != SQLITE_ROW);
1.6 bertrand 1402:
1403: if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT)
1404: {
1405: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1406: return;
1407: }
1408:
1409: tampon = (*s_etat_processus).instruction_courante;
1410:
1411: if ((tampon_lecture = (unsigned char *)
1412: sqlite3_column_text(ppStmt, 0)) == NULL)
1413: {
1414: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1415: return;
1416: }
1417:
1418: if (((*s_etat_processus).instruction_courante =
1419: transliteration(s_etat_processus, tampon_lecture,
1420: "UTF-8", d_locale)) == NULL)
1421: {
1422: (*s_etat_processus).instruction_courante = tampon;
1423:
1424: liberation(s_etat_processus, s_objet_argument_1);
1425: liberation(s_etat_processus, s_objet_argument_2);
1426: free(commande);
1427: return;
1428: }
1429:
1430: indicateur_48 = test_cfsf(s_etat_processus, 48);
1431: cf(s_etat_processus, 48);
1432:
1.90 bertrand 1433: (*s_etat_processus).type_en_cours = NON;
1.6 bertrand 1434: recherche_type(s_etat_processus);
1435:
1436: if ((*s_etat_processus).erreur_execution != d_ex)
1437: {
1438: if (indicateur_48 == d_vrai)
1439: {
1440: sf(s_etat_processus, 48);
1441: }
1442: else
1443: {
1444: cf(s_etat_processus, 48);
1445: }
1446:
1447: liberation(s_etat_processus, s_objet_argument_1);
1448: liberation(s_etat_processus, s_objet_argument_2);
1449:
1450: free((*s_etat_processus).instruction_courante);
1451: free(commande);
1.8 bertrand 1452:
1453: (*s_etat_processus).instruction_courante = tampon;
1.6 bertrand 1454: return;
1455: }
1456:
1457: if (indicateur_48 == d_vrai)
1458: {
1459: sf(s_etat_processus, 48);
1460: }
1461: else
1462: {
1463: cf(s_etat_processus, 48);
1464: }
1465:
1466: free((*s_etat_processus).instruction_courante);
1467: liberation(s_etat_processus, s_objet_argument_2);
1468: (*s_etat_processus).instruction_courante = tampon;
1469:
1470: if (sqlite3_step(ppStmt) != SQLITE_DONE)
1471: {
1472: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1473: return;
1474: }
1475:
1476: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1477: {
1478: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1479: return;
1480: }
1481:
1482: free(commande);
1.1 bertrand 1483: }
1484: else
1485: {
1.8 bertrand 1486: BUG(((*descripteur).type != 'S'), uprintf("Bad filtype !\n"));
1487:
1488: if (depilement(s_etat_processus, &((*s_etat_processus)
1489: .l_base_pile), &s_objet_argument_2) == d_erreur)
1490: {
1491: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1492: return;
1493: }
1494:
1495: if ((*s_objet_argument_2).type != CHN)
1496: {
1497: liberation(s_etat_processus, s_objet_argument_1);
1498: liberation(s_etat_processus, s_objet_argument_2);
1499:
1500: (*s_etat_processus).erreur_execution =
1501: d_ex_erreur_type_argument;
1502: return;
1503: }
1504:
1505: // Récupération de la position de la clef
1506:
1.93 bertrand 1507: if (alsprintf(s_etat_processus, &commande,
1508: "select key from control where id = 1") < 0)
1.8 bertrand 1509: {
1510: (*s_etat_processus).erreur_systeme =
1511: d_es_allocation_memoire;
1512: return;
1513: }
1514:
1515: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1516: commande, (int) strlen(commande), &ppStmt, &queue)
1.8 bertrand 1517: != SQLITE_OK)
1518: {
1519: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1520: return;
1521: }
1522:
1.68 bertrand 1523: attente.tv_sec = 0;
1524: attente.tv_nsec = GRANULARITE_us * 1000;
1525:
1526: do
1.8 bertrand 1527: {
1.68 bertrand 1528: ios = sqlite3_step(ppStmt);
1529:
1530: if (ios == SQLITE_ROW)
1531: {
1532: break;
1533: }
1534: else if ((ios == SQLITE_BUSY) || (ios == SQLITE_LOCKED))
1535: {
1536: nanosleep(&attente, NULL);
1537: INCR_GRANULARITE(attente.tv_nsec);
1538: }
1539: else
1540: {
1541: (*s_etat_processus).erreur_systeme =
1542: d_es_erreur_fichier;
1543: return;
1544: }
1545: } while(ios != SQLITE_ROW);
1.8 bertrand 1546:
1547: if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
1548: {
1549: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1550: return;
1551: }
1552:
1553: position_clef = sqlite3_column_int64(ppStmt, 0);
1554:
1555: if (sqlite3_step(ppStmt) != SQLITE_DONE)
1556: {
1557: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1558: return;
1559: }
1560:
1561: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1562: {
1563: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1564: return;
1565: }
1566:
1567: free(commande);
1568:
1569: if ((clef_utf8 = transliteration(s_etat_processus,
1570: (unsigned char *) (*s_objet_argument_2).objet,
1571: d_locale, "UTF-8")) == NULL)
1572: {
1573: liberation(s_etat_processus, s_objet_argument_1);
1574: liberation(s_etat_processus, s_objet_argument_2);
1575:
1576: return;
1577: }
1578:
1579: // Récupération de l'identifiant de la clef
1580:
1.93 bertrand 1581: if (alsprintf(s_etat_processus, &commande,
1582: "select id from key where key = '{ \"%s\" }'",
1583: clef_utf8) < 0)
1.8 bertrand 1584: {
1585: (*s_etat_processus).erreur_systeme =
1586: d_es_allocation_memoire;
1587: return;
1588: }
1589:
1590: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1591: commande, (int) strlen(commande), &ppStmt, &queue)
1.8 bertrand 1592: != SQLITE_OK)
1593: {
1594: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1595: return;
1596: }
1597:
1.68 bertrand 1598: attente.tv_sec = 0;
1599: attente.tv_nsec = GRANULARITE_us * 1000;
1600:
1601: do
1.8 bertrand 1602: {
1.68 bertrand 1603: ios = sqlite3_step(ppStmt);
1.8 bertrand 1604:
1.68 bertrand 1605: switch(ios)
1.8 bertrand 1606: {
1.68 bertrand 1607: case SQLITE_ROW:
1.8 bertrand 1608: {
1.68 bertrand 1609: // Résultat attendu : une clef correspond.
1610: break;
1.8 bertrand 1611: }
1612:
1.68 bertrand 1613: case SQLITE_DONE:
1614: {
1615: // Aucun enregistrement
1616: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1617: {
1618: (*s_etat_processus).erreur_systeme =
1619: d_es_erreur_fichier;
1620: return;
1621: }
1622:
1623: free(clef_utf8);
1624: free(commande);
1625:
1626: liberation(s_etat_processus, s_objet_argument_1);
1627: liberation(s_etat_processus, s_objet_argument_2);
1.8 bertrand 1628:
1.68 bertrand 1629: (*s_etat_processus).erreur_execution =
1630: d_ex_enregistrement_inexistant;
1631: return;
1632: }
1.8 bertrand 1633:
1.68 bertrand 1634: case SQLITE_BUSY:
1635: case SQLITE_LOCKED:
1636: {
1637: nanosleep(&attente, NULL);
1638: INCR_GRANULARITE(attente.tv_nsec);
1639: break;
1640: }
1.8 bertrand 1641:
1.68 bertrand 1642: default:
1643: {
1644: (*s_etat_processus).erreur_systeme =
1645: d_es_erreur_fichier;
1646: return;
1647: }
1.8 bertrand 1648: }
1.68 bertrand 1649: } while(ios != SQLITE_ROW);
1.8 bertrand 1650:
1651: if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
1652: {
1653: free(clef_utf8);
1654: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1655: return;
1656: }
1657:
1658: id = sqlite3_column_int64(ppStmt, 0);
1659:
1660: if (sqlite3_step(ppStmt) != SQLITE_DONE)
1661: {
1662: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1663: return;
1664: }
1665:
1666: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1667: {
1668: (*s_etat_processus).erreur_systeme =
1669: d_es_erreur_fichier;
1670: return;
1671: }
1672:
1673: free(commande);
1674:
1.93 bertrand 1675: if (alsprintf(s_etat_processus, &commande,
1676: "select data from data where "
1.8 bertrand 1677: "key_id = %lld order by sequence asc", id) < 0)
1678: {
1679: (*s_etat_processus).erreur_systeme =
1680: d_es_allocation_memoire;
1681: return;
1682: }
1683:
1684: if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.76 bertrand 1685: commande, (int) strlen(commande), &ppStmt, &queue)
1.8 bertrand 1686: != SQLITE_OK)
1687: {
1688: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1689: return;
1690: }
1691:
1692: element = 1;
1693:
1.68 bertrand 1694: attente.tv_sec = 0;
1695: attente.tv_nsec = GRANULARITE_us * 1000;
1696:
1.8 bertrand 1697: do
1698: {
1699: switch(ios = sqlite3_step(ppStmt))
1700: {
1701: case SQLITE_ROW:
1702: {
1703: // Donnée supplémentaire
1704:
1705: if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT)
1706: {
1707: (*s_etat_processus).erreur_systeme =
1708: d_es_erreur_fichier;
1709: return;
1710: }
1711:
1712: tampon = (*s_etat_processus).instruction_courante;
1713:
1714: if ((tampon_lecture = (unsigned char *)
1715: sqlite3_column_text(ppStmt, 0)) == NULL)
1716: {
1717: (*s_etat_processus).erreur_systeme =
1718: d_es_erreur_fichier;
1719: return;
1720: }
1721:
1722: if (((*s_etat_processus).instruction_courante =
1723: transliteration(s_etat_processus,
1724: tampon_lecture,
1725: "UTF-8", d_locale)) == NULL)
1726: {
1727: (*s_etat_processus).instruction_courante =
1728: tampon;
1729:
1730: liberation(s_etat_processus,
1731: s_objet_argument_1);
1732: liberation(s_etat_processus,
1733: s_objet_argument_2);
1734:
1735: free(commande);
1736: free(clef_utf8);
1737: return;
1738: }
1739:
1740: indicateur_48 = test_cfsf(s_etat_processus, 48);
1741: cf(s_etat_processus, 48);
1742:
1.90 bertrand 1743: (*s_etat_processus).type_en_cours = NON;
1.8 bertrand 1744: recherche_type(s_etat_processus);
1745:
1746: if ((*s_etat_processus).erreur_execution != d_ex)
1747: {
1748: if (indicateur_48 == d_vrai)
1749: {
1750: sf(s_etat_processus, 48);
1751: }
1752: else
1753: {
1754: cf(s_etat_processus, 48);
1755: }
1756:
1757: liberation(s_etat_processus,
1758: s_objet_argument_1);
1759: liberation(s_etat_processus,
1760: s_objet_argument_2);
1761:
1762: free((*s_etat_processus).instruction_courante);
1763: free(commande);
1764: free(clef_utf8);
1765:
1766: (*s_etat_processus).instruction_courante =
1767: tampon;
1768: return;
1769: }
1770:
1771: if (indicateur_48 == d_vrai)
1772: {
1773: sf(s_etat_processus, 48);
1774: }
1775: else
1776: {
1777: cf(s_etat_processus, 48);
1778: }
1779:
1780: free((*s_etat_processus).instruction_courante);
1781: (*s_etat_processus).instruction_courante = tampon;
1782:
1783: element++;
1784:
1785: // Inscription de la clef
1786:
1787: if (element == position_clef)
1788: {
1789: if (((*s_etat_processus).instruction_courante =
1790: transliteration(s_etat_processus,
1791: clef_utf8, "UTF-8", d_locale)) == NULL)
1792: {
1793: (*s_etat_processus).instruction_courante =
1794: tampon;
1795:
1796: liberation(s_etat_processus,
1797: s_objet_argument_1);
1798: liberation(s_etat_processus,
1799: s_objet_argument_2);
1800:
1801: free(commande);
1802: free(clef_utf8);
1803: return;
1804: }
1805:
1.93 bertrand 1806: if (alsprintf(s_etat_processus, &tampon2,
1807: "{ \"%s\" }", (*s_etat_processus)
1.8 bertrand 1808: .instruction_courante) < 0)
1809: {
1810: (*s_etat_processus).erreur_systeme =
1811: d_es_allocation_memoire;
1812: return;
1813: }
1814:
1815: free((*s_etat_processus).instruction_courante);
1816: (*s_etat_processus).instruction_courante
1817: = tampon2;
1818:
1819: indicateur_48 = test_cfsf(s_etat_processus, 48);
1820: cf(s_etat_processus, 48);
1821:
1.90 bertrand 1822: (*s_etat_processus).type_en_cours = NON;
1.8 bertrand 1823: recherche_type(s_etat_processus);
1824:
1825: if ((*s_etat_processus).erreur_execution
1826: != d_ex)
1827: {
1828: if (indicateur_48 == d_vrai)
1829: {
1830: sf(s_etat_processus, 48);
1831: }
1832: else
1833: {
1834: cf(s_etat_processus, 48);
1835: }
1836:
1837: liberation(s_etat_processus,
1838: s_objet_argument_1);
1839: liberation(s_etat_processus,
1840: s_objet_argument_2);
1841:
1842: free((*s_etat_processus)
1843: .instruction_courante);
1844: free(commande);
1845: free(clef_utf8);
1846:
1847: (*s_etat_processus).instruction_courante =
1848: tampon;
1849: return;
1850: }
1851:
1852: if (indicateur_48 == d_vrai)
1853: {
1854: sf(s_etat_processus, 48);
1855: }
1856: else
1857: {
1858: cf(s_etat_processus, 48);
1859: }
1860:
1861: free((*s_etat_processus).instruction_courante);
1862: (*s_etat_processus).instruction_courante =
1863: tampon;
1864:
1865: element++;
1866: }
1867:
1868: break;
1869: }
1870:
1871: case SQLITE_DONE:
1872: {
1873: // Fin de la liste
1874: break;
1875: }
1876:
1.68 bertrand 1877: case SQLITE_BUSY:
1878: case SQLITE_LOCKED:
1879: {
1880: nanosleep(&attente, NULL);
1881: INCR_GRANULARITE(attente.tv_nsec);
1882: break;
1883: }
1884:
1.8 bertrand 1885: default:
1886: {
1887: (*s_etat_processus).erreur_systeme =
1888: d_es_erreur_fichier;
1889: return;
1890: }
1891: }
1892: } while(ios != SQLITE_DONE);
1893:
1894: if (sqlite3_finalize(ppStmt) != SQLITE_OK)
1895: {
1896: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1897: return;
1898: }
1899:
1900: free(commande);
1901: free(clef_utf8);
1902:
1903: liberation(s_etat_processus, s_objet_argument_2);
1904:
1905: if ((s_objet_resultat = allocation(s_etat_processus, LST))
1906: == NULL)
1907: {
1908: (*s_etat_processus).erreur_systeme =
1909: d_es_allocation_memoire;
1910: return;
1911: }
1912:
1913: l_element_courant = NULL;
1.9 bertrand 1914: l_element_inclus = NULL;
1.8 bertrand 1915:
1916: for(element--; element > 0; element--)
1917: {
1918: if (depilement(s_etat_processus, &((*s_etat_processus)
1919: .l_base_pile), &s_objet_argument_2) == d_erreur)
1920: {
1921: (*s_etat_processus).erreur_systeme =
1922: d_es_erreur_fichier;
1923: return;
1924: }
1925:
1926: if ((*s_objet_argument_2).type != LST)
1927: {
1928: (*s_etat_processus).erreur_systeme =
1929: d_es_erreur_fichier;
1930: return;
1931: }
1932:
1933: l_element_inclus = (*s_objet_argument_2).objet;
1934:
1935: if (l_element_inclus != NULL)
1936: {
1937: while(l_element_inclus != NULL)
1938: {
1939: if ((*l_element_inclus).suivant == NULL)
1940: {
1941: (*l_element_inclus).suivant = l_element_courant;
1942: break;
1943: }
1944:
1945: l_element_inclus = (*l_element_inclus).suivant;
1946: }
1947:
1948: l_element_courant = (*s_objet_argument_2).objet;
1949: (*s_objet_argument_2).objet = NULL;
1950: }
1951:
1952: liberation(s_etat_processus, s_objet_argument_2);
1953: }
1954:
1955: (*s_objet_resultat).objet = l_element_inclus;
1956:
1957: if (empilement(s_etat_processus,
1958: &((*s_etat_processus).l_base_pile),
1959: s_objet_resultat) == d_erreur)
1960: {
1961: return;
1962: }
1.1 bertrand 1963: }
1964: }
1.6 bertrand 1965: else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
1.1 bertrand 1966: == 'Y')
1967: {
1968: /*
1969: * Fichiers non formatés
1970: */
1.46 bertrand 1971:
1972: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1973: == 'S')
1974: {
1975: /*
1976: * Fichiers séquentiels
1977: *
1978: * Les fichiers séquentiels non formatés contiennent comme
1979: * les fichiers séquentiels formatés leurs enregistrements
1980: * sous la forme de listes les unes derrières les autres.
1981: *
1982: * Le quartet de poids fort du premier octet à lire
1983: * doit donc être égal à 0100. Si ce n'est pas le cas,
1984: * il sera impossible de lire le fichier et on renvoie
1985: * immédiatement une erreur. Si on lit dans le fichier
1986: * la valeur attendue, on récupère la longueur en octet
1987: * de l'enregistrement puis on le lit.
1988: */
1989:
1990: BUG(((*descripteur).type != 'C'), uprintf("Bad filtype !\n"));
1991:
1.72 bertrand 1992: if ((s_objet_resultat = lecture_fichier_non_formate(
1993: s_etat_processus, (*descripteur).descripteur_c, -1,
1994: d_faux)) == NULL)
1.46 bertrand 1995: {
1996: return;
1997: }
1998:
1.72 bertrand 1999: if (empilement(s_etat_processus,
2000: &((*s_etat_processus).l_base_pile),
2001: s_objet_resultat) == d_erreur)
1.46 bertrand 2002: {
2003: return;
2004: }
2005: }
1.1 bertrand 2006: }
2007: else
2008: {
2009: /*
2010: * Fichiers de type FLOW
2011: */
1.28 bertrand 2012:
2013: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
2014: == 'S')
2015: {
2016: /*
2017: * Fichiers séquentiels
2018: */
2019:
2020: BUG(((*descripteur).type != 'C'), uprintf("Bad filtype !\n"));
2021: longueur_enregistrement = 0;
1.84 bertrand 2022:
1.82 bertrand 2023: device = d_faux;
1.28 bertrand 2024:
2025: if ((position_initiale = ftell((*descripteur).descripteur_c))
2026: == -1)
2027: {
1.82 bertrand 2028: if (errno == ESPIPE)
2029: {
2030: device = d_vrai;
2031: }
2032: else
2033: {
2034: (*s_etat_processus).erreur_systeme =
2035: d_es_erreur_fichier;
2036: return;
2037: }
1.28 bertrand 2038: }
2039:
1.59 bertrand 2040: l_element_courant_format = (struct_liste_chainee *)
2041: (*(*((struct_fichier *) (*s_objet_argument_1).objet))
2042: .format).objet;
2043: l_element_courant = NULL;
1.28 bertrand 2044:
2045: if ((s_objet_resultat = allocation(s_etat_processus, LST))
2046: == NULL)
2047: {
2048: (*s_etat_processus).erreur_systeme =
2049: d_es_allocation_memoire;
2050: return;
2051: }
2052:
1.59 bertrand 2053: while(l_element_courant_format != NULL)
1.28 bertrand 2054: {
1.59 bertrand 2055: if ((*(*l_element_courant_format).donnee).type != CHN)
2056: {
2057: liberation(s_etat_processus, s_objet_argument_1);
2058: liberation(s_etat_processus, s_objet_resultat);
2059:
2060: (*s_etat_processus).erreur_execution =
2061: d_ex_erreur_type_argument;
2062: return;
2063: }
2064:
1.93 bertrand 2065: if ((format_chaine = conversion_majuscule(
2066: s_etat_processus, (unsigned char *)
1.59 bertrand 2067: (*(*l_element_courant_format).donnee).objet))
2068: == NULL)
2069: {
2070: (*s_etat_processus).erreur_systeme =
2071: d_es_allocation_memoire;
2072: return;
2073: }
2074:
2075: if (strncmp("LENGTH*(", format_chaine, 8) != 0)
2076: {
2077: liberation(s_etat_processus, s_objet_argument_1);
2078: liberation(s_etat_processus, s_objet_resultat);
2079: free(format_chaine);
2080:
2081: (*s_etat_processus).erreur_execution =
2082: d_ex_erreur_format_fichier;
2083: return;
2084: }
2085:
1.76 bertrand 2086: longueur = (integer8) strlen(format_chaine);
1.59 bertrand 2087:
1.60 bertrand 2088: if (format_chaine[longueur - 1] != ')')
1.59 bertrand 2089: {
2090: liberation(s_etat_processus, s_objet_argument_1);
2091: liberation(s_etat_processus, s_objet_resultat);
2092: free(format_chaine);
2093:
2094: (*s_etat_processus).erreur_execution =
2095: d_ex_erreur_format_fichier;
2096: return;
2097: }
2098:
2099: format_chaine[longueur] = d_code_fin_chaine;
2100:
2101: if (format_chaine[8] == '*')
2102: {
2103: format_degenere = d_vrai;
2104: }
2105: else
2106: {
2107: // Détermination de la longueur
2108: format_degenere = d_faux;
2109:
1.77 bertrand 2110: if (sscanf(&(format_chaine[8]), "%lld", &longueur) != 1)
1.59 bertrand 2111: {
2112: liberation(s_etat_processus, s_objet_argument_1);
2113: liberation(s_etat_processus, s_objet_resultat);
2114: free(format_chaine);
2115:
2116: (*s_etat_processus).erreur_execution =
2117: d_ex_erreur_format_fichier;
2118: return;
2119: }
2120: }
2121:
2122: free(format_chaine);
1.84 bertrand 2123: tampon3 = NULL;
1.59 bertrand 2124:
2125: if (format_degenere == d_vrai)
2126: {
1.84 bertrand 2127: if (device == d_vrai)
2128: {
2129: longueur_questure = 4096;
2130: index = 0;
2131:
2132: if ((tampon3 = malloc(((size_t) longueur_questure) *
2133: sizeof(unsigned char))) == NULL)
2134: {
2135: (*s_etat_processus).erreur_systeme =
2136: d_es_allocation_memoire;
2137: return;
2138: }
2139:
2140: tampon3[index] = d_code_fin_chaine;
2141:
2142: fds[0].fd = fileno((*descripteur).descripteur_c);
2143: fds[0].events = POLLIN;
2144: fds[0].revents = 0;
2145:
2146: tcgetattr(fileno((*descripteur).descripteur_c),
2147: &tc);
2148: timeout = 0;
2149:
2150: for(i = 0; vitesses[i] != 0; i++)
2151: {
2152: if (cfgetispeed(&tc) == vitesses_constantes[i])
2153: {
2154: // La durée entre deux caractères sur le
2155: // périphérique série ne doit pas dépasser
2156: // la moitié de la durée de transmission
2157: // d'un caractère complet.
2158:
2159: timeout = (int) (((double) 1000) /
2160: (((double) vitesses_constantes[i]) /
2161: 4));
2162: break;
2163: }
2164: }
2165: }
1.99 bertrand 2166: else
2167: {
2168: // Évite un warning de gcc.
2169: longueur_questure = 0;
2170: index = 0;
2171: timeout = 0;
2172: }
1.84 bertrand 2173:
1.59 bertrand 2174: do
2175: {
1.84 bertrand 2176: if (device == d_vrai)
2177: {
2178: if (poll(fds, 1, timeout) == 0)
2179: {
2180: break;
2181: }
2182: }
2183:
1.59 bertrand 2184: c = getc((*descripteur).descripteur_c);
2185: longueur_enregistrement++;
1.84 bertrand 2186:
2187: if (device == d_vrai)
2188: {
2189: if (longueur_enregistrement >=
2190: longueur_questure)
2191: {
2192: if ((tampon3 = realloc(tampon3,
2193: (size_t) (longueur_questure *= 2)))
2194: == NULL)
2195: {
2196: (*s_etat_processus).erreur_systeme =
2197: d_es_allocation_memoire;
2198: return;
2199: }
2200: }
2201:
2202: tampon3[index++] = (unsigned char) c;
2203: }
2204: } while(c != EOF);
1.59 bertrand 2205:
1.82 bertrand 2206: if (device == d_faux)
1.59 bertrand 2207: {
1.82 bertrand 2208: if (fseek((*descripteur).descripteur_c,
2209: (long) position_initiale, SEEK_SET) != 0)
2210: {
2211: liberation(s_etat_processus,
2212: s_objet_argument_1);
2213: liberation(s_etat_processus, s_objet_resultat);
1.59 bertrand 2214:
1.82 bertrand 2215: (*s_etat_processus).erreur_systeme =
2216: d_es_erreur_fichier;
2217: return;
2218: }
1.59 bertrand 2219: }
2220: }
2221: else
2222: {
2223: longueur_enregistrement = longueur;
2224: }
2225:
1.84 bertrand 2226: if ((device == d_vrai) && (format_degenere == d_vrai))
1.59 bertrand 2227: {
1.84 bertrand 2228: longueur_effective = longueur_enregistrement;
2229: tampon_lecture = tampon3;
1.59 bertrand 2230: }
1.84 bertrand 2231: else
2232: {
2233: if ((tampon_lecture = malloc(((size_t)
2234: longueur_enregistrement) *
2235: sizeof(unsigned char))) == NULL)
2236: {
2237: (*s_etat_processus).erreur_systeme =
2238: d_es_allocation_memoire;
2239: return;
2240: }
1.59 bertrand 2241:
1.84 bertrand 2242: longueur_effective = (integer8) fread(tampon_lecture,
2243: sizeof(unsigned char),
2244: (size_t) longueur_enregistrement,
2245: (*descripteur).descripteur_c);
2246: }
1.59 bertrand 2247:
2248: if (l_element_courant == NULL)
2249: {
2250: // Premier maillon de la liste
2251: if (((*s_objet_resultat).objet =
2252: allocation_maillon(s_etat_processus)) == NULL)
2253: {
2254: (*s_etat_processus).erreur_systeme =
2255: d_es_allocation_memoire;
2256: return;
2257: }
2258:
2259: l_element_courant = (*s_objet_resultat).objet;
2260: }
2261: else
2262: {
2263: if (((*l_element_courant).suivant =
2264: allocation_maillon(s_etat_processus)) == NULL)
2265: {
2266: (*s_etat_processus).erreur_systeme =
2267: d_es_allocation_memoire;
2268: return;
2269: }
2270:
2271: l_element_courant = (*l_element_courant).suivant;
2272: }
2273:
2274: (*l_element_courant).suivant = NULL;
2275:
2276: if (((*l_element_courant).donnee =
2277: allocation(s_etat_processus, CHN)) == NULL)
2278: {
2279: (*s_etat_processus).erreur_systeme =
2280: d_es_allocation_memoire;
2281: return;
2282: }
1.28 bertrand 2283:
1.59 bertrand 2284: if (format_degenere == d_vrai)
2285: {
1.84 bertrand 2286: if (device == d_faux)
2287: {
2288: if (((*(*l_element_courant).donnee).objet =
2289: analyse_flux(s_etat_processus, tampon_lecture,
2290: longueur_enregistrement - 1)) == NULL)
2291: {
2292: return;
2293: }
2294: }
2295: else
1.59 bertrand 2296: {
1.84 bertrand 2297: if (((*(*l_element_courant).donnee).objet =
2298: analyse_flux(s_etat_processus, tampon_lecture,
2299: longueur_enregistrement)) == NULL)
2300: {
2301: return;
2302: }
1.59 bertrand 2303: }
2304: }
2305: else
2306: {
2307: if (((*(*l_element_courant).donnee).objet =
2308: analyse_flux(s_etat_processus, tampon_lecture,
2309: longueur_enregistrement)) == NULL)
2310: {
2311: return;
2312: }
2313: }
1.28 bertrand 2314:
1.59 bertrand 2315: free(tampon_lecture);
1.28 bertrand 2316:
1.59 bertrand 2317: l_element_courant_format =
2318: (*l_element_courant_format).suivant;
1.28 bertrand 2319: }
2320:
2321: if (empilement(s_etat_processus,
2322: &((*s_etat_processus).l_base_pile),
2323: s_objet_resultat) == d_erreur)
2324: {
2325: return;
2326: }
2327: }
2328: else
2329: {
2330: liberation(s_etat_processus, s_objet_argument_1);
2331:
2332: (*s_etat_processus).erreur_execution =
2333: d_ex_erreur_type_fichier;
2334: return;
2335: }
1.1 bertrand 2336: }
2337: }
1.6 bertrand 2338: else if ((*s_objet_argument_1).type == SCK)
1.1 bertrand 2339: {
2340: /*
2341: * Vérification de l'autorisation de lecture
2342: */
2343:
1.6 bertrand 2344: if ((*((struct_socket *) (*s_objet_argument_1).objet)).protection
2345: == 'W')
1.1 bertrand 2346: {
1.6 bertrand 2347: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2348:
2349: (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
2350: return;
2351: }
2352:
2353: /*
2354: * Vérification de l'écoute de la socket si celle-ci est connectée
2355: */
2356:
1.6 bertrand 2357: if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
1.1 bertrand 2358: "STREAM") == 0) || (strcmp((*((struct_socket *)
1.6 bertrand 2359: (*s_objet_argument_1).objet)).type, "SEQUENTIAL DATAGRAM")
2360: == 0))
1.1 bertrand 2361: {
1.6 bertrand 2362: if ((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2363: .socket_en_ecoute == 'Y')
2364: {
1.6 bertrand 2365: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2366:
2367: (*s_etat_processus).erreur_execution = d_ex_socket_en_ecoute;
2368: return;
2369: }
2370: }
2371:
1.6 bertrand 2372: if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
1.1 bertrand 2373: { // Socket formatée
1.71 bertrand 2374: longueur_questure = 4096;
1.55 bertrand 2375: longueur_effective = 0;
2376: tampon_lecture = NULL;
1.1 bertrand 2377:
1.56 bertrand 2378: attente.tv_sec = 0;
2379: attente.tv_nsec = GRANULARITE_us * 1000;
2380:
1.57 bertrand 2381: trame_complete = d_faux;
2382: position_initiale = 0;
2383: position_finale = 0;
2384:
1.1 bertrand 2385: do
2386: {
1.55 bertrand 2387: presence_indicateur = d_faux;
2388:
2389: if ((tampon_lecture = realloc(tampon_lecture,
1.76 bertrand 2390: ((size_t) (longueur_effective + longueur_questure + 1))
1.55 bertrand 2391: * sizeof(unsigned char))) == NULL)
1.1 bertrand 2392: {
2393: (*s_etat_processus).erreur_systeme =
2394: d_es_allocation_memoire;
2395: return;
2396: }
2397:
1.44 bertrand 2398: # ifndef SEMAPHORES_NOMMES
2399: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
2400: # else
2401: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2402: # endif
1.1 bertrand 2403: {
2404: (*s_etat_processus).erreur_systeme = d_es_processus;
2405: return;
2406: }
2407:
1.55 bertrand 2408: if ((*((struct_socket *) (*s_objet_argument_1).objet))
2409: .domaine == PF_UNIX)
2410: {
2411: longueur_adresse = sizeof(adresse_unix);
1.57 bertrand 2412:
2413: do
2414: {
1.76 bertrand 2415: ios = (int) recvfrom((*((struct_socket *)
1.57 bertrand 2416: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2417: tampon_lecture, (size_t) (longueur_effective +
2418: longueur_questure),
1.57 bertrand 2419: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
2420: &adresse_unix, &longueur_adresse);
2421: } while((ios == -1) && (errno == EINTR));
1.55 bertrand 2422: }
2423: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
2424: .domaine == PF_INET)
2425: {
2426: longueur_adresse = sizeof(adresse_ipv4);
1.57 bertrand 2427:
2428: do
2429: {
1.76 bertrand 2430: ios = (int) recvfrom((*((struct_socket *)
1.57 bertrand 2431: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2432: tampon_lecture, (size_t) (longueur_effective +
2433: longueur_questure),
1.57 bertrand 2434: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
2435: &adresse_ipv4, &longueur_adresse);
2436: } while((ios == -1) && (errno == EINTR));
1.55 bertrand 2437: }
2438: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
2439: .domaine == PF_INET6)
2440: {
2441: # ifdef IPV6
2442: longueur_adresse = sizeof(adresse_ipv6);
1.57 bertrand 2443:
2444: do
2445: {
1.76 bertrand 2446: ios = (int) recvfrom((*((struct_socket *)
1.57 bertrand 2447: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2448: tampon_lecture, (size_t) (longueur_effective +
2449: longueur_questure),
1.57 bertrand 2450: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
2451: &adresse_ipv6, &longueur_adresse);
2452: } while((ios == -1) && (errno == EINTR));
1.55 bertrand 2453: # else
2454: if ((*s_etat_processus).langue == 'F')
2455: {
2456: printf("+++Attention : Support du protocole"
2457: " IPv6 indisponible\n");
2458: }
2459: else
2460: {
2461: printf("+++Warning : IPv6 support "
2462: "unavailable\n");
2463: }
2464:
2465: longueur_adresse = 0;
2466: longueur_effective = 0;
2467: ios = 0;
2468: # endif
2469: }
2470: else
2471: {
2472: free(tampon_lecture);
2473: liberation(s_etat_processus, s_objet_argument_1);
2474:
2475: # ifndef SEMAPHORES_NOMMES
2476: while(sem_wait(&((*s_etat_processus)
2477: .semaphore_fork)) != 0)
2478: # else
2479: while(sem_wait((*s_etat_processus)
2480: .semaphore_fork) != 0)
2481: # endif
2482: {
2483: (*s_etat_processus).erreur_systeme =
2484: d_es_processus;
2485: }
2486:
2487: (*s_etat_processus).erreur_execution =
2488: d_ex_erreur_acces_fichier;
2489: return;
2490: }
2491:
1.74 bertrand 2492: if (ios <= 0)
1.55 bertrand 2493: {
2494: nanosleep(&attente, NULL);
2495: INCR_GRANULARITE(attente.tv_nsec);
2496: }
1.56 bertrand 2497: else
2498: {
2499: attente.tv_sec = 0;
2500: attente.tv_nsec = GRANULARITE_us * 1000;
2501: }
1.55 bertrand 2502:
1.74 bertrand 2503: scrutation_injection(s_etat_processus);
2504:
1.55 bertrand 2505: if ((*s_etat_processus).var_volatile_requete_arret == -1)
2506: {
1.62 bertrand 2507: if (ios >= 0)
2508: {
1.74 bertrand 2509: longueur_effective = ios;
1.62 bertrand 2510: }
2511:
1.55 bertrand 2512: break;
2513: }
2514:
2515: // Une donnée a été reçue.
2516:
2517: if (ios >= 0)
1.1 bertrand 2518: {
1.74 bertrand 2519: longueur_effective = ios;
1.55 bertrand 2520: position_initiale = 0;
2521: presence_indicateur = d_faux;
2522:
2523: do
2524: {
2525: if (tampon_lecture[position_initiale] == '{')
2526: {
2527: presence_indicateur = d_vrai;
2528: break;
2529: }
2530:
2531: position_initiale++;
2532: } while(position_initiale < longueur_effective);
2533:
2534: if (presence_indicateur == d_vrai)
2535: {
2536: position_finale = position_initiale + 1;
2537: presence_chaine = d_faux;
2538: presence_indicateur = d_faux;
2539: niveau = 1;
2540:
2541: while(position_finale < longueur_effective)
2542: {
2543: caractere = tampon_lecture[position_finale];
2544:
2545: if (caractere == '"')
2546: {
1.59 bertrand 2547: if (position_finale > 0)
2548: {
2549: if (tampon_lecture[position_finale - 1]
2550: != '\\')
2551: {
2552: presence_chaine = (presence_chaine ==
2553: d_vrai) ? d_faux : d_vrai;
2554: }
2555: }
2556: else
2557: {
2558: presence_chaine =
2559: (presence_chaine == d_vrai)
2560: ? d_faux : d_vrai;
2561: }
1.55 bertrand 2562: }
2563: else
2564: {
2565: if (presence_chaine == d_faux)
2566: {
2567: if (caractere == '{')
2568: {
2569: niveau++;
2570: }
2571: else if (caractere == '}')
2572: {
2573: niveau--;
2574: }
2575: }
2576: }
2577:
2578: if (niveau == 0)
2579: {
2580: presence_indicateur = d_vrai;
1.57 bertrand 2581: trame_complete = d_vrai;
1.55 bertrand 2582: break;
2583: }
2584:
2585: position_finale++;
2586: }
2587: }
2588:
1.71 bertrand 2589: // On retire une trame du buffer.
1.55 bertrand 2590:
1.71 bertrand 2591: if (trame_complete == d_vrai)
1.1 bertrand 2592: {
1.71 bertrand 2593: if ((*((struct_socket *) (*s_objet_argument_1).objet))
2594: .domaine == PF_UNIX)
1.57 bertrand 2595: {
1.71 bertrand 2596: do
2597: {
2598: longueur_adresse = sizeof(adresse_unix);
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_unix, &longueur_adresse);
2605: } while((ios == -1) && (errno == EINTR));
2606: }
2607: else if ((*((struct_socket *) (*s_objet_argument_1)
2608: .objet)).domaine == PF_INET)
1.57 bertrand 2609: {
1.71 bertrand 2610: do
2611: {
2612: longueur_adresse = sizeof(adresse_ipv4);
2613: recvfrom((*((struct_socket *)
2614: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2615: tampon_lecture,
2616: (size_t) longueur_effective,
1.71 bertrand 2617: 0, (struct sockaddr *)
2618: &adresse_ipv4, &longueur_adresse);
2619: } while((ios == -1) && (errno == EINTR));
1.21 bertrand 2620: }
1.71 bertrand 2621: else if ((*((struct_socket *) (*s_objet_argument_1)
2622: .objet)) .domaine == PF_INET6)
1.21 bertrand 2623: {
1.71 bertrand 2624: # ifdef IPV6
2625: do
2626: {
2627: longueur_adresse = sizeof(adresse_ipv6);
2628: recvfrom((*((struct_socket *)
2629: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 2630: tampon_lecture,
2631: (size_t) longueur_effective,
1.71 bertrand 2632: 0, (struct sockaddr *)
2633: &adresse_ipv6, &longueur_adresse);
2634: } while((ios == -1) && (errno == EINTR));
2635: # else
2636: if ((*s_etat_processus).langue == 'F')
2637: {
2638: printf("+++Attention : Support du protocole"
2639: " IPv6 indisponible\n");
2640: }
2641: else
2642: {
2643: printf("+++Warning : IPv6 support "
2644: "unavailable\n");
2645: }
2646:
2647: # endif
1.21 bertrand 2648: }
1.51 bertrand 2649:
1.71 bertrand 2650: longueur_effective = ios;
1.1 bertrand 2651: }
1.71 bertrand 2652: else
2653: {
1.79 bertrand 2654: // Si on a lu toute une trame et qu'on n'a pas
2655: // réussi à en trouver la structure, on remonte
2656: // une erreur de syntaxe.
1.1 bertrand 2657:
1.79 bertrand 2658: if (longueur_effective == ios)
1.1 bertrand 2659: {
1.79 bertrand 2660: if ((*((struct_socket *) (*s_objet_argument_1)
2661: .objet)).domaine == PF_UNIX)
2662: {
2663: do
2664: {
2665: longueur_adresse = sizeof(adresse_unix);
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_unix, &longueur_adresse);
2672: } while((ios == -1) && (errno == EINTR));
2673: }
2674: else if ((*((struct_socket *) (*s_objet_argument_1)
2675: .objet)).domaine == PF_INET)
2676: {
2677: do
2678: {
2679: longueur_adresse = sizeof(adresse_ipv4);
2680: recvfrom((*((struct_socket *)
2681: (*s_objet_argument_1).objet))
2682: .socket, tampon_lecture,
2683: (size_t) longueur_effective,
2684: 0, (struct sockaddr *)
2685: &adresse_ipv4, &longueur_adresse);
2686: } while((ios == -1) && (errno == EINTR));
2687: }
2688: else if ((*((struct_socket *) (*s_objet_argument_1)
2689: .objet)) .domaine == PF_INET6)
1.55 bertrand 2690: {
1.79 bertrand 2691: # ifdef IPV6
2692: do
1.55 bertrand 2693: {
1.79 bertrand 2694: longueur_adresse = sizeof(adresse_ipv6);
2695: recvfrom((*((struct_socket *)
2696: (*s_objet_argument_1).objet))
2697: .socket, tampon_lecture,
2698: (size_t) longueur_effective,
2699: 0, (struct sockaddr *)
2700: &adresse_ipv6, &longueur_adresse);
2701: } while((ios == -1) && (errno == EINTR));
2702: # else
2703: if ((*s_etat_processus).langue == 'F')
2704: {
2705: printf("+++Attention : Support du protocole"
2706: " IPv6 indisponible\n");
1.55 bertrand 2707: }
1.79 bertrand 2708: else
1.55 bertrand 2709: {
1.79 bertrand 2710: printf("+++Warning : IPv6 support "
2711: "unavailable\n");
2712: }
1.1 bertrand 2713:
1.79 bertrand 2714: # endif
1.55 bertrand 2715: }
1.79 bertrand 2716:
2717: liberation(s_etat_processus, s_objet_argument_1);
2718: free(tampon_lecture);
2719:
2720: (*s_etat_processus).erreur_execution = d_ex_syntaxe;
2721: return;
1.55 bertrand 2722: }
1.1 bertrand 2723: }
2724: }
2725:
1.44 bertrand 2726: # ifndef SEMAPHORES_NOMMES
2727: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
2728: # else
2729: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2730: # endif
1.1 bertrand 2731: {
1.44 bertrand 2732: if (errno == EINTR)
1.43 bertrand 2733: {
2734: (*s_etat_processus).erreur_systeme = d_es_processus;
2735: return;
2736: }
1.1 bertrand 2737: }
2738:
2739: if ((*s_etat_processus).var_volatile_requete_arret == -1)
2740: {
2741:
2742: /*
2743: * Si le père tue le processus courant grâce au signal
2744: * SIGFSTOP, on ne renvoie pas d'erreur. Ce fonctionnement
2745: * correspond à l'utilisation de STOP sur le processus
2746: * en cours. La variable longueur_effective vaut '-1'.
2747: */
2748:
2749: free(tampon_lecture);
1.6 bertrand 2750: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2751: return;
2752: }
2753:
2754: if (longueur_effective == -1)
2755: {
2756: free(tampon_lecture);
1.6 bertrand 2757: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2758:
2759: (*s_etat_processus).erreur_execution =
2760: d_ex_erreur_acces_fichier;
2761: return;
2762: }
1.57 bertrand 2763: } while(trame_complete == d_faux);
1.1 bertrand 2764:
2765: tampon_lecture[++position_finale] = d_code_fin_chaine;
2766: tampon = (*s_etat_processus).instruction_courante;
1.71 bertrand 2767: (*s_etat_processus).instruction_courante = tampon_lecture;
1.1 bertrand 2768:
2769: indicateur_48 = test_cfsf(s_etat_processus, 48);
2770: cf(s_etat_processus, 48);
2771:
1.90 bertrand 2772: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 2773: recherche_type(s_etat_processus);
2774:
2775: if ((*s_etat_processus).erreur_execution != d_ex)
2776: {
2777: (*s_etat_processus).instruction_courante = tampon;
2778: free(tampon_lecture);
2779:
1.57 bertrand 2780: if (indicateur_48 == d_vrai)
2781: {
2782: sf(s_etat_processus, 48);
2783: }
2784: else
2785: {
2786: cf(s_etat_processus, 48);
2787: }
2788:
2789: if ((*s_etat_processus).var_volatile_requete_arret == -1)
2790: {
2791: (*s_etat_processus).erreur_execution = d_ex;
2792: }
2793:
1.6 bertrand 2794: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 2795: return;
2796: }
2797:
2798: if (indicateur_48 == d_vrai)
2799: {
2800: sf(s_etat_processus, 48);
2801: }
2802: else
2803: {
2804: cf(s_etat_processus, 48);
2805: }
2806:
2807: (*s_etat_processus).instruction_courante = tampon;
2808:
2809: /*
2810: * Création de la liste de sortie
2811: */
2812:
2813: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2814: &s_objet_type) == d_erreur)
2815: {
2816: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2817: return;
2818: }
2819:
2820: if ((s_objet_resultat = allocation(s_etat_processus, LST))
2821: == NULL)
2822: {
2823: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2824: return;
2825: }
2826:
2827: if (((*s_objet_resultat).objet =
2828: allocation_maillon(s_etat_processus)) == NULL)
2829: {
2830: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2831: return;
2832: }
2833:
2834: (*((struct_liste_chainee *) (*s_objet_resultat).objet))
2835: .donnee = s_objet_type;
2836:
2837: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet))
2838: .suivant = allocation_maillon(s_etat_processus)) == NULL)
2839: {
2840: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2841: return;
2842: }
2843:
2844: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
2845: .suivant = NULL;
2846:
2847: if ((s_objet_adresse = allocation(s_etat_processus, LST))
2848: == NULL)
2849: {
2850: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2851: return;
2852: }
2853:
2854: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
2855: .donnee = s_objet_adresse;
2856:
2857: /*
2858: * Les informations concernant la cible sont valides si
2859: * la socket est non connectée et des domaines INET ou INET6.
2860: * Dans tous les autres cas, on renvoie une liste vide.
2861: */
2862:
1.6 bertrand 2863: if (((*((struct_socket *) (*s_objet_argument_1).objet)).domaine
1.1 bertrand 2864: == PF_UNIX) || (strcmp((*((struct_socket *)
1.6 bertrand 2865: (*s_objet_argument_1).objet)).type, "STREAM") == 0) ||
2866: (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2867: .type, "SEQUENTIAL DATAGRAM") == 0))
2868: {
2869: (*s_objet_adresse).objet = NULL;
2870: }
1.6 bertrand 2871: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2872: .domaine == PF_INET)
2873: {
2874: if (((*s_objet_adresse).objet =
2875: allocation_maillon(s_etat_processus)) == NULL)
2876: {
2877: (*s_etat_processus).erreur_systeme =
2878: d_es_allocation_memoire;
2879: return;
2880: }
2881:
2882: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2883: .donnee = allocation(s_etat_processus, VIN)) == NULL)
2884: {
2885: (*s_etat_processus).erreur_systeme =
2886: d_es_allocation_memoire;
2887: return;
2888: }
2889:
2890: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
2891: (*s_objet_adresse).objet)).donnee).objet)).taille = 4;
2892:
2893: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
2894: (*s_objet_adresse).objet)).donnee).objet)).tableau =
2895: malloc(4 * sizeof(integer8))) == NULL)
2896: {
2897: (*s_etat_processus).erreur_systeme =
2898: d_es_allocation_memoire;
2899: return;
2900: }
2901:
2902: ((integer8 *) (*((struct_vecteur *)
2903: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2904: .objet)).donnee).objet)).tableau)[0] =
2905: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF;
2906: ((integer8 *) (*((struct_vecteur *)
2907: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2908: .objet)).donnee).objet)).tableau)[1] =
2909: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF;
2910: ((integer8 *) (*((struct_vecteur *)
2911: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2912: .objet)).donnee).objet)).tableau)[2] =
2913: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF;
2914: ((integer8 *) (*((struct_vecteur *)
2915: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2916: .objet)).donnee).objet)).tableau)[3] =
2917: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF;
2918:
2919: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2920: .suivant = allocation_maillon(s_etat_processus))
2921: == NULL)
2922: {
2923: (*s_etat_processus).erreur_systeme =
2924: d_es_allocation_memoire;
2925: return;
2926: }
2927:
2928: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2929: .suivant).donnee = allocation(s_etat_processus, INT))
2930: == NULL)
2931: {
2932: (*s_etat_processus).erreur_systeme =
2933: d_es_allocation_memoire;
2934: return;
2935: }
2936:
2937: (*((integer8 *) (*(*(*((struct_liste_chainee *)
1.6 bertrand 2938: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
1.1 bertrand 2939: (integer8) ntohs(adresse_ipv4.sin_port);
2940:
2941: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2942: .suivant).suivant = NULL;
2943: }
1.6 bertrand 2944: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
1.1 bertrand 2945: .domaine == PF_INET6)
2946: {
1.19 bertrand 2947: # ifdef IPV6
1.1 bertrand 2948: if (((*s_objet_adresse).objet =
2949: allocation_maillon(s_etat_processus)) == NULL)
2950: {
2951: (*s_etat_processus).erreur_systeme =
2952: d_es_allocation_memoire;
2953: return;
2954: }
2955:
2956: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2957: .donnee = allocation(s_etat_processus, VIN)) == NULL)
2958: {
2959: (*s_etat_processus).erreur_systeme =
2960: d_es_allocation_memoire;
2961: return;
2962: }
2963:
2964: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
2965: (*s_objet_adresse).objet)).donnee).objet)).taille = 16;
2966:
2967: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
2968: (*s_objet_adresse).objet)).donnee).objet)).tableau =
2969: malloc(16 * sizeof(integer8))) == NULL)
2970: {
2971: (*s_etat_processus).erreur_systeme =
2972: d_es_allocation_memoire;
2973: return;
2974: }
2975:
2976: for(i = 0; i < 16; i++)
2977: {
2978: ((integer8 *) (*((struct_vecteur *)
2979: (*(*((struct_liste_chainee *) (*s_objet_adresse)
2980: .objet)).donnee).objet)).tableau)[0] =
2981: adresse_ipv6.sin6_addr.s6_addr[i];
2982: }
2983:
2984: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
2985: .suivant = allocation_maillon(s_etat_processus))
2986: == NULL)
2987: {
2988: (*s_etat_processus).erreur_systeme =
2989: d_es_allocation_memoire;
2990: return;
2991: }
2992:
2993: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
2994: .suivant).donnee = allocation(s_etat_processus, INT))
2995: == NULL)
2996: {
2997: (*s_etat_processus).erreur_systeme =
2998: d_es_allocation_memoire;
2999: return;
3000: }
3001:
3002: (*((integer8 *) (*(*(*((struct_liste_chainee *)
1.6 bertrand 3003: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
1.1 bertrand 3004: (integer8) ntohs(adresse_ipv6.sin6_port);
3005:
3006: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3007: .suivant).suivant = NULL;
1.19 bertrand 3008: # else
1.21 bertrand 3009: if ((*s_etat_processus).langue == 'F')
3010: {
3011: printf("+++Attention : Support du protocole"
1.22 bertrand 3012: " IPv6 indisponible\n");
1.21 bertrand 3013: }
3014: else
3015: {
1.23 bertrand 3016: printf("+++Warning : IPv6 support "
1.21 bertrand 3017: "unavailable\n");
3018: }
1.19 bertrand 3019: # endif
1.1 bertrand 3020: }
3021: else
3022: {
3023: longueur_adresse = 0;
3024: recvfrom((*((struct_socket *)
1.6 bertrand 3025: (*s_objet_argument_1).objet)).socket, tampon_lecture,
1.76 bertrand 3026: (size_t) position_finale, MSG_DONTWAIT,
1.1 bertrand 3027: NULL, &longueur_adresse);
3028: }
3029:
3030: free(tampon_lecture);
3031:
3032: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3033: s_objet_resultat) == d_erreur)
3034: {
3035: return;
3036: }
3037: }
1.28 bertrand 3038: else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
3039: == 'Y')
1.73 bertrand 3040: { // socket non formatée
3041: longueur_questure = 4096;
3042: longueur_effective = 0;
3043: tampon_lecture = NULL;
3044:
3045: attente.tv_sec = 0;
3046: attente.tv_nsec = GRANULARITE_us * 1000;
3047:
3048: trame_complete = d_faux;
3049: position_initiale = 0;
3050: position_finale = 0;
3051:
3052: do
3053: {
3054: presence_indicateur = d_faux;
3055:
3056: if ((tampon_lecture = realloc(tampon_lecture,
1.76 bertrand 3057: ((size_t) (longueur_effective + longueur_questure) + 1)
1.73 bertrand 3058: * sizeof(unsigned char))) == NULL)
3059: {
3060: (*s_etat_processus).erreur_systeme =
3061: d_es_allocation_memoire;
3062: return;
3063: }
3064:
3065: # ifndef SEMAPHORES_NOMMES
3066: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3067: # else
3068: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3069: # endif
3070: {
3071: (*s_etat_processus).erreur_systeme = d_es_processus;
3072: return;
3073: }
3074:
3075: if ((*((struct_socket *) (*s_objet_argument_1).objet))
3076: .domaine == PF_UNIX)
3077: {
3078: longueur_adresse = sizeof(adresse_unix);
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_unix, &longueur_adresse);
3088: } while((ios == -1) && (errno == EINTR));
3089: }
3090: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3091: .domaine == PF_INET)
3092: {
3093: longueur_adresse = sizeof(adresse_ipv4);
3094:
3095: do
3096: {
1.76 bertrand 3097: ios = (int) recvfrom((*((struct_socket *)
1.73 bertrand 3098: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3099: tampon_lecture, (size_t)
3100: (longueur_effective + longueur_questure),
1.73 bertrand 3101: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3102: &adresse_ipv4, &longueur_adresse);
3103: } while((ios == -1) && (errno == EINTR));
3104: }
3105: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3106: .domaine == PF_INET6)
3107: {
3108: # ifdef IPV6
3109: longueur_adresse = sizeof(adresse_ipv6);
3110:
3111: do
3112: {
1.76 bertrand 3113: ios = (int) recvfrom((*((struct_socket *)
1.73 bertrand 3114: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3115: tampon_lecture, (size_t)
3116: (longueur_effective + longueur_questure),
1.73 bertrand 3117: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3118: &adresse_ipv6, &longueur_adresse);
3119: } while((ios == -1) && (errno == EINTR));
3120: # else
3121: if ((*s_etat_processus).langue == 'F')
3122: {
3123: printf("+++Attention : Support du protocole"
3124: " IPv6 indisponible\n");
3125: }
3126: else
3127: {
3128: printf("+++Warning : IPv6 support "
3129: "unavailable\n");
3130: }
3131:
3132: longueur_adresse = 0;
3133: longueur_effective = 0;
3134: ios = 0;
3135: # endif
3136: }
3137: else
3138: {
3139: free(tampon_lecture);
3140: liberation(s_etat_processus, s_objet_argument_1);
3141:
3142: # ifndef SEMAPHORES_NOMMES
3143: while(sem_wait(&((*s_etat_processus)
3144: .semaphore_fork)) != 0)
3145: # else
3146: while(sem_wait((*s_etat_processus)
3147: .semaphore_fork) != 0)
3148: # endif
3149: {
3150: (*s_etat_processus).erreur_systeme =
3151: d_es_processus;
3152: }
3153:
3154: (*s_etat_processus).erreur_execution =
3155: d_ex_erreur_acces_fichier;
3156: return;
3157: }
3158:
1.74 bertrand 3159: if (ios <= 0)
1.73 bertrand 3160: {
3161: nanosleep(&attente, NULL);
3162: INCR_GRANULARITE(attente.tv_nsec);
3163: }
3164: else
3165: {
3166: attente.tv_sec = 0;
3167: attente.tv_nsec = GRANULARITE_us * 1000;
3168: }
3169:
1.74 bertrand 3170: scrutation_injection(s_etat_processus);
3171:
1.73 bertrand 3172: if ((*s_etat_processus).var_volatile_requete_arret == -1)
3173: {
3174: if (ios >= 0)
3175: {
3176: longueur_effective += ios;
3177: }
3178:
3179: break;
3180: }
3181:
3182: // Une donnée a été reçue.
3183:
1.74 bertrand 3184: if (ios == (longueur_effective + longueur_questure))
1.73 bertrand 3185: {
1.74 bertrand 3186: longueur_effective = ios;
1.73 bertrand 3187: position_initiale = 0;
3188: presence_indicateur = d_faux;
1.74 bertrand 3189: }
3190: else if (ios > 0)
3191: {
3192: // On retire une trame du buffer.
1.73 bertrand 3193:
1.74 bertrand 3194: if ((*((struct_socket *) (*s_objet_argument_1).objet))
3195: .domaine == PF_UNIX)
1.73 bertrand 3196: {
1.74 bertrand 3197: do
1.73 bertrand 3198: {
1.74 bertrand 3199: longueur_adresse = sizeof(adresse_unix);
3200: recvfrom((*((struct_socket *)
3201: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3202: tampon_lecture, (size_t) longueur_effective,
1.74 bertrand 3203: 0, (struct sockaddr *)
3204: &adresse_unix, &longueur_adresse);
3205: } while((ios == -1) && (errno == EINTR));
3206: }
3207: else if ((*((struct_socket *) (*s_objet_argument_1)
3208: .objet)).domaine == PF_INET)
1.73 bertrand 3209: {
1.74 bertrand 3210: do
1.73 bertrand 3211: {
1.74 bertrand 3212: longueur_adresse = sizeof(adresse_ipv4);
3213: recvfrom((*((struct_socket *)
3214: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3215: tampon_lecture, (size_t) longueur_effective,
1.74 bertrand 3216: 0, (struct sockaddr *)
3217: &adresse_ipv4, &longueur_adresse);
3218: } while((ios == -1) && (errno == EINTR));
1.73 bertrand 3219: }
1.74 bertrand 3220: else if ((*((struct_socket *) (*s_objet_argument_1)
3221: .objet)) .domaine == PF_INET6)
1.73 bertrand 3222: {
1.74 bertrand 3223: # ifdef IPV6
3224: do
1.73 bertrand 3225: {
1.74 bertrand 3226: longueur_adresse = sizeof(adresse_ipv6);
3227: recvfrom((*((struct_socket *)
3228: (*s_objet_argument_1).objet)).socket,
1.76 bertrand 3229: tampon_lecture, (size_t) longueur_effective,
1.74 bertrand 3230: 0, (struct sockaddr *)
3231: &adresse_ipv6, &longueur_adresse);
3232: } while((ios == -1) && (errno == EINTR));
3233: # else
3234: if ((*s_etat_processus).langue == 'F')
1.73 bertrand 3235: {
1.74 bertrand 3236: printf("+++Attention : Support du protocole"
3237: " IPv6 indisponible\n");
1.73 bertrand 3238: }
1.74 bertrand 3239: else
1.73 bertrand 3240: {
1.74 bertrand 3241: printf("+++Warning : IPv6 support "
3242: "unavailable\n");
1.73 bertrand 3243: }
1.74 bertrand 3244: # endif
1.73 bertrand 3245: }
3246:
1.74 bertrand 3247: longueur_effective = ios;
3248: trame_complete = d_vrai;
1.73 bertrand 3249: }
3250:
3251: # ifndef SEMAPHORES_NOMMES
3252: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3253: # else
3254: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3255: # endif
3256: {
3257: if (errno == EINTR)
3258: {
3259: (*s_etat_processus).erreur_systeme = d_es_processus;
3260: return;
3261: }
3262: }
3263:
3264: if ((*s_etat_processus).var_volatile_requete_arret == -1)
3265: {
3266:
3267: /*
3268: * Si le père tue le processus courant grâce au signal
3269: * SIGFSTOP, on ne renvoie pas d'erreur. Ce fonctionnement
3270: * correspond à l'utilisation de STOP sur le processus
3271: * en cours. La variable longueur_effective vaut '-1'.
3272: */
3273:
3274: free(tampon_lecture);
3275: liberation(s_etat_processus, s_objet_argument_1);
3276: return;
3277: }
3278:
3279: if (longueur_effective == -1)
3280: {
3281: free(tampon_lecture);
3282: liberation(s_etat_processus, s_objet_argument_1);
3283:
3284: (*s_etat_processus).erreur_execution =
3285: d_ex_erreur_acces_fichier;
3286: return;
3287: }
3288: } while(trame_complete == d_faux);
3289:
1.74 bertrand 3290: /*
3291: * Création de la liste de sortie
3292: */
1.73 bertrand 3293:
1.74 bertrand 3294: ptr = tampon_lecture;
1.73 bertrand 3295:
1.74 bertrand 3296: if ((s_objet_type = lecture_fichier_non_formate(s_etat_processus,
3297: &ptr, longueur_effective, d_faux)) == NULL)
1.73 bertrand 3298: {
3299: free(tampon_lecture);
3300:
1.74 bertrand 3301: (*s_etat_processus).erreur_execution = d_ex_syntaxe;
1.73 bertrand 3302: return;
3303: }
3304:
3305: if ((s_objet_resultat = allocation(s_etat_processus, LST))
3306: == NULL)
3307: {
3308: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3309: return;
3310: }
3311:
3312: if (((*s_objet_resultat).objet =
3313: allocation_maillon(s_etat_processus)) == NULL)
3314: {
3315: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3316: return;
3317: }
3318:
3319: (*((struct_liste_chainee *) (*s_objet_resultat).objet))
3320: .donnee = s_objet_type;
3321:
3322: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet))
3323: .suivant = allocation_maillon(s_etat_processus)) == NULL)
3324: {
3325: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3326: return;
3327: }
3328:
3329: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3330: .suivant = NULL;
3331:
3332: if ((s_objet_adresse = allocation(s_etat_processus, LST))
3333: == NULL)
3334: {
3335: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3336: return;
3337: }
3338:
3339: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3340: .donnee = s_objet_adresse;
3341:
3342: /*
3343: * Les informations concernant la cible sont valides si
3344: * la socket est non connectée et des domaines INET ou INET6.
3345: * Dans tous les autres cas, on renvoie une liste vide.
3346: */
3347:
3348: if (((*((struct_socket *) (*s_objet_argument_1).objet)).domaine
3349: == PF_UNIX) || (strcmp((*((struct_socket *)
3350: (*s_objet_argument_1).objet)).type, "STREAM") == 0) ||
3351: (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
3352: .type, "SEQUENTIAL DATAGRAM") == 0))
3353: {
3354: (*s_objet_adresse).objet = NULL;
3355: }
3356: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3357: .domaine == PF_INET)
3358: {
3359: if (((*s_objet_adresse).objet =
3360: allocation_maillon(s_etat_processus)) == NULL)
3361: {
3362: (*s_etat_processus).erreur_systeme =
3363: d_es_allocation_memoire;
3364: return;
3365: }
3366:
3367: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3368: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3369: {
3370: (*s_etat_processus).erreur_systeme =
3371: d_es_allocation_memoire;
3372: return;
3373: }
3374:
3375: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3376: (*s_objet_adresse).objet)).donnee).objet)).taille = 4;
3377:
3378: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3379: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3380: malloc(4 * sizeof(integer8))) == NULL)
3381: {
3382: (*s_etat_processus).erreur_systeme =
3383: d_es_allocation_memoire;
3384: return;
3385: }
3386:
3387: ((integer8 *) (*((struct_vecteur *)
3388: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3389: .objet)).donnee).objet)).tableau)[0] =
3390: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF;
3391: ((integer8 *) (*((struct_vecteur *)
3392: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3393: .objet)).donnee).objet)).tableau)[1] =
3394: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF;
3395: ((integer8 *) (*((struct_vecteur *)
3396: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3397: .objet)).donnee).objet)).tableau)[2] =
3398: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF;
3399: ((integer8 *) (*((struct_vecteur *)
3400: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3401: .objet)).donnee).objet)).tableau)[3] =
3402: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF;
3403:
3404: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3405: .suivant = allocation_maillon(s_etat_processus))
3406: == NULL)
3407: {
3408: (*s_etat_processus).erreur_systeme =
3409: d_es_allocation_memoire;
3410: return;
3411: }
3412:
3413: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3414: .suivant).donnee = allocation(s_etat_processus, INT))
3415: == NULL)
3416: {
3417: (*s_etat_processus).erreur_systeme =
3418: d_es_allocation_memoire;
3419: return;
3420: }
3421:
3422: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3423: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3424: (integer8) ntohs(adresse_ipv4.sin_port);
3425:
3426: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3427: .suivant).suivant = NULL;
3428: }
3429: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3430: .domaine == PF_INET6)
3431: {
3432: # ifdef IPV6
3433: if (((*s_objet_adresse).objet =
3434: allocation_maillon(s_etat_processus)) == NULL)
3435: {
3436: (*s_etat_processus).erreur_systeme =
3437: d_es_allocation_memoire;
3438: return;
3439: }
3440:
3441: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3442: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3443: {
3444: (*s_etat_processus).erreur_systeme =
3445: d_es_allocation_memoire;
3446: return;
3447: }
3448:
3449: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3450: (*s_objet_adresse).objet)).donnee).objet)).taille = 16;
3451:
3452: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3453: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3454: malloc(16 * sizeof(integer8))) == NULL)
3455: {
3456: (*s_etat_processus).erreur_systeme =
3457: d_es_allocation_memoire;
3458: return;
3459: }
3460:
3461: for(i = 0; i < 16; i++)
3462: {
3463: ((integer8 *) (*((struct_vecteur *)
3464: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3465: .objet)).donnee).objet)).tableau)[0] =
3466: adresse_ipv6.sin6_addr.s6_addr[i];
3467: }
3468:
3469: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3470: .suivant = allocation_maillon(s_etat_processus))
3471: == NULL)
3472: {
3473: (*s_etat_processus).erreur_systeme =
3474: d_es_allocation_memoire;
3475: return;
3476: }
3477:
3478: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3479: .suivant).donnee = allocation(s_etat_processus, INT))
3480: == NULL)
3481: {
3482: (*s_etat_processus).erreur_systeme =
3483: d_es_allocation_memoire;
3484: return;
3485: }
3486:
3487: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3488: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3489: (integer8) ntohs(adresse_ipv6.sin6_port);
3490:
3491: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3492: .suivant).suivant = NULL;
3493: # else
3494: if ((*s_etat_processus).langue == 'F')
3495: {
3496: printf("+++Attention : Support du protocole"
3497: " IPv6 indisponible\n");
3498: }
3499: else
3500: {
3501: printf("+++Warning : IPv6 support "
3502: "unavailable\n");
3503: }
3504: # endif
3505: }
3506: else
3507: {
3508: longueur_adresse = 0;
3509: recvfrom((*((struct_socket *)
3510: (*s_objet_argument_1).objet)).socket, tampon_lecture,
1.76 bertrand 3511: (size_t) position_finale, MSG_DONTWAIT,
1.73 bertrand 3512: NULL, &longueur_adresse);
3513: }
3514:
3515: free(tampon_lecture);
3516:
3517: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3518: s_objet_resultat) == d_erreur)
3519: {
3520: return;
3521: }
1.28 bertrand 3522: }
1.1 bertrand 3523: else
1.28 bertrand 3524: { // FLOW
1.73 bertrand 3525: #if 0
1.28 bertrand 3526: longueur_questure = 256;
3527:
3528: do
3529: {
3530: if ((tampon_lecture = malloc((longueur_questure + 1) *
3531: sizeof(unsigned char))) == NULL)
3532: {
3533: (*s_etat_processus).erreur_systeme =
3534: d_es_allocation_memoire;
3535: return;
3536: }
3537:
1.44 bertrand 3538: # ifndef SEMAPHORES_NOMMES
3539: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3540: # else
3541: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3542: # endif
1.28 bertrand 3543: {
3544: (*s_etat_processus).erreur_systeme = d_es_processus;
3545: return;
3546: }
3547:
1.30 bertrand 3548: attente.tv_sec = 0;
3549: attente.tv_nsec = GRANULARITE_us * 1000;
3550:
1.28 bertrand 3551: for(;;)
3552: {
3553: if ((*((struct_socket *) (*s_objet_argument_1).objet))
3554: .domaine == PF_UNIX)
3555: {
3556: longueur_adresse = sizeof(adresse_unix);
3557: longueur_effective = recvfrom((*((struct_socket *)
3558: (*s_objet_argument_1).objet)).socket,
3559: tampon_lecture, longueur_questure,
3560: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3561: &adresse_unix, &longueur_adresse);
3562: }
3563: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3564: .domaine == PF_INET)
3565: {
3566: longueur_adresse = sizeof(adresse_ipv4);
3567: longueur_effective = recvfrom((*((struct_socket *)
3568: (*s_objet_argument_1).objet)).socket,
3569: tampon_lecture, longueur_questure,
3570: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3571: &adresse_ipv4, &longueur_adresse);
3572: }
3573: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3574: .domaine == PF_INET6)
3575: {
3576: # ifdef IPV6
3577: longueur_adresse = sizeof(adresse_ipv6);
3578: longueur_effective = recvfrom((*((struct_socket *)
3579: (*s_objet_argument_1).objet)).socket,
3580: tampon_lecture, longueur_questure,
3581: MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
3582: &adresse_ipv6, &longueur_adresse);
3583: # else
3584: if ((*s_etat_processus).langue == 'F')
3585: {
3586: printf("+++Attention : Support du protocole"
3587: " IPv6 indisponible\n");
3588: }
3589: else
3590: {
3591: printf("+++Warning : IPv6 support "
3592: "unavailable\n");
3593: }
1.51 bertrand 3594:
3595: longueur_adresse = 0;
3596: longueur_effective = 0;
1.28 bertrand 3597: # endif
3598: }
3599: else
3600: {
3601: free(tampon_lecture);
3602: liberation(s_etat_processus, s_objet_argument_1);
3603:
1.44 bertrand 3604: # ifndef SEMAPHORES_NOMMES
3605: while(sem_wait(&((*s_etat_processus)
3606: .semaphore_fork)) != 0)
3607: # else
3608: while(sem_wait((*s_etat_processus)
3609: .semaphore_fork) != 0)
3610: # endif
1.28 bertrand 3611: {
1.43 bertrand 3612: if (errno != EINTR)
3613: {
3614: (*s_etat_processus).erreur_systeme =
3615: d_es_processus;
3616: return;
3617: }
1.28 bertrand 3618: }
3619:
3620: (*s_etat_processus).erreur_execution =
3621: d_ex_erreur_acces_fichier;
3622: return;
3623: }
3624:
3625: if (longueur_effective < 0)
3626: {
3627: nanosleep(&attente, NULL);
1.30 bertrand 3628: INCR_GRANULARITE(attente.tv_nsec);
1.28 bertrand 3629: scrutation_injection(s_etat_processus);
3630: }
3631:
3632: if (((*s_etat_processus).var_volatile_requete_arret == -1)
3633: || (longueur_effective >= 0))
3634: {
3635: break;
3636: }
3637: }
3638:
1.44 bertrand 3639: # ifndef SEMAPHORES_NOMMES
3640: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3641: # else
3642: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3643: # endif
1.28 bertrand 3644: {
1.43 bertrand 3645: if (errno != EINTR)
3646: {
3647: (*s_etat_processus).erreur_systeme = d_es_processus;
3648: return;
3649: }
1.28 bertrand 3650: }
3651:
3652: if ((*s_etat_processus).var_volatile_requete_arret == -1)
3653: {
3654:
3655: /*
3656: * Si le père tue le processus courant grâce au signal
3657: * SIGFSTOP, on ne renvoie pas d'erreur. Ce fonctionnement
3658: * correspond à l'utilisation de STOP sur le processus
3659: * en cours. La variable longueur_effective vaut '-1'.
3660: */
3661:
3662: free(tampon_lecture);
3663: liberation(s_etat_processus, s_objet_argument_1);
3664: return;
3665: }
3666:
3667: if (longueur_effective == -1)
3668: {
3669: free(tampon_lecture);
3670: liberation(s_etat_processus, s_objet_argument_1);
3671:
3672: (*s_etat_processus).erreur_execution =
3673: d_ex_erreur_acces_fichier;
3674: return;
3675: }
3676:
3677: if (longueur_effective == longueur_questure)
3678: {
3679: free(tampon_lecture);
3680: longueur_questure *= 2;
3681: }
3682: } while(longueur_effective == longueur_questure);
3683:
3684: longueur_enregistrement = 1;
3685:
3686: for(i = 0; i < longueur_effective; i++)
3687: {
3688: if (isprint(tampon_lecture[i]) != 0)
3689: {
3690: longueur_enregistrement += 4;
3691: }
3692: else
3693: {
3694: longueur_enregistrement++;
3695: }
3696: }
3697:
3698: /*
3699: * Création de la liste de sortie
3700: */
3701:
3702: if ((s_objet_type = allocation(s_etat_processus, CHN)) == NULL)
3703: {
3704: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3705: return;
3706: }
3707:
3708: if (((*s_objet_type).objet = malloc(longueur_enregistrement *
3709: sizeof(unsigned char))) == NULL)
3710: {
3711: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3712: return;
3713: }
3714:
3715: ptr = (*s_objet_type).objet;
3716:
3717: for(i = 0; i < longueur_effective; i++)
3718: {
3719: if (isprint(tampon_lecture[i]) != 0)
3720: {
3721: (*ptr) = tampon_lecture[i];
3722: ptr++;
3723: }
3724: else
3725: {
3726: (*ptr) = '\\';
3727: ptr++;
3728: (*ptr) = 'x';
3729: ptr++;
3730: sprintf(ptr, "%02X", tampon_lecture[i]);
3731: ptr += 2;
3732: }
3733: }
3734:
3735: (*ptr) = d_code_fin_chaine;
3736:
3737: if ((s_objet_resultat = allocation(s_etat_processus, LST))
3738: == NULL)
3739: {
3740: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3741: return;
3742: }
3743:
3744: if (((*s_objet_resultat).objet =
3745: allocation_maillon(s_etat_processus)) == NULL)
3746: {
3747: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3748: return;
3749: }
3750:
3751: (*((struct_liste_chainee *) (*s_objet_resultat).objet))
3752: .donnee = s_objet_type;
3753:
3754: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet))
3755: .suivant = allocation_maillon(s_etat_processus)) == NULL)
3756: {
3757: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3758: return;
3759: }
3760:
3761: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3762: .suivant = NULL;
3763:
3764: if ((s_objet_adresse = allocation(s_etat_processus, LST))
3765: == NULL)
3766: {
3767: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3768: return;
3769: }
3770:
3771: (*(*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)
3772: .donnee = s_objet_adresse;
3773:
3774: /*
3775: * Les informations concernant la cible sont valides si
1.30 bertrand 3776: * la socket est non connectée et que les domaines sont
3777: * INET ou INET6.
1.28 bertrand 3778: * Dans tous les autres cas, on renvoie une liste vide.
3779: */
3780:
3781: if (((*((struct_socket *) (*s_objet_argument_1).objet)).domaine
3782: == PF_UNIX) || (strcmp((*((struct_socket *)
3783: (*s_objet_argument_1).objet)).type, "STREAM") == 0) ||
3784: (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
3785: .type, "SEQUENTIAL DATAGRAM") == 0))
3786: {
1.30 bertrand 3787: // POSITION_FINALE peut être utilisée sans être initialisée !
3788: // virer position_finale pour longueur_effective
1.28 bertrand 3789: longueur_adresse = 0;
3790: recvfrom((*((struct_socket *)
3791: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3792: position_finale, MSG_DONTWAIT,
3793: NULL, &longueur_adresse);
3794:
3795: (*s_objet_adresse).objet = NULL;
3796: }
3797: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3798: .domaine == PF_INET)
3799: {
3800: longueur_adresse = sizeof(adresse_ipv4);
3801: recvfrom((*((struct_socket *)
3802: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3803: position_finale, MSG_DONTWAIT,
3804: (struct sockaddr *) &adresse_ipv4, &longueur_adresse);
3805:
3806: if (((*s_objet_adresse).objet =
3807: allocation_maillon(s_etat_processus)) == NULL)
3808: {
3809: (*s_etat_processus).erreur_systeme =
3810: d_es_allocation_memoire;
3811: return;
3812: }
3813:
3814: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3815: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3816: {
3817: (*s_etat_processus).erreur_systeme =
3818: d_es_allocation_memoire;
3819: return;
3820: }
3821:
3822: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3823: (*s_objet_adresse).objet)).donnee).objet)).taille = 4;
3824:
3825: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3826: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3827: malloc(4 * sizeof(integer8))) == NULL)
3828: {
3829: (*s_etat_processus).erreur_systeme =
3830: d_es_allocation_memoire;
3831: return;
3832: }
3833:
3834: ((integer8 *) (*((struct_vecteur *)
3835: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3836: .objet)).donnee).objet)).tableau)[0] =
3837: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF;
3838: ((integer8 *) (*((struct_vecteur *)
3839: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3840: .objet)).donnee).objet)).tableau)[1] =
3841: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF;
3842: ((integer8 *) (*((struct_vecteur *)
3843: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3844: .objet)).donnee).objet)).tableau)[2] =
3845: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF;
3846: ((integer8 *) (*((struct_vecteur *)
3847: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3848: .objet)).donnee).objet)).tableau)[3] =
3849: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF;
3850:
3851: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3852: .suivant = allocation_maillon(s_etat_processus))
3853: == NULL)
3854: {
3855: (*s_etat_processus).erreur_systeme =
3856: d_es_allocation_memoire;
3857: return;
3858: }
3859:
3860: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3861: .suivant).donnee = allocation(s_etat_processus, INT))
3862: == NULL)
3863: {
3864: (*s_etat_processus).erreur_systeme =
3865: d_es_allocation_memoire;
3866: return;
3867: }
3868:
3869: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3870: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3871: (integer8) ntohs(adresse_ipv4.sin_port);
3872:
3873: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3874: .suivant).suivant = NULL;
3875: }
3876: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
3877: .domaine == PF_INET6)
3878: {
3879: # ifdef IPV6
3880: longueur_adresse = sizeof(adresse_ipv6);
3881: recvfrom((*((struct_socket *)
3882: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3883: position_finale, MSG_DONTWAIT,
3884: (struct sockaddr *) &adresse_ipv6, &longueur_adresse);
3885:
3886: if (((*s_objet_adresse).objet =
3887: allocation_maillon(s_etat_processus)) == NULL)
3888: {
3889: (*s_etat_processus).erreur_systeme =
3890: d_es_allocation_memoire;
3891: return;
3892: }
3893:
3894: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3895: .donnee = allocation(s_etat_processus, VIN)) == NULL)
3896: {
3897: (*s_etat_processus).erreur_systeme =
3898: d_es_allocation_memoire;
3899: return;
3900: }
3901:
3902: (*((struct_vecteur *) (*(*((struct_liste_chainee *)
3903: (*s_objet_adresse).objet)).donnee).objet)).taille = 16;
3904:
3905: if (((*((struct_vecteur *) (*(*((struct_liste_chainee *)
3906: (*s_objet_adresse).objet)).donnee).objet)).tableau =
3907: malloc(16 * sizeof(integer8))) == NULL)
3908: {
3909: (*s_etat_processus).erreur_systeme =
3910: d_es_allocation_memoire;
3911: return;
3912: }
3913:
3914: for(i = 0; i < 16; i++)
3915: {
3916: ((integer8 *) (*((struct_vecteur *)
3917: (*(*((struct_liste_chainee *) (*s_objet_adresse)
3918: .objet)).donnee).objet)).tableau)[0] =
3919: adresse_ipv6.sin6_addr.s6_addr[i];
3920: }
3921:
3922: if (((*((struct_liste_chainee *) (*s_objet_adresse).objet))
3923: .suivant = allocation_maillon(s_etat_processus))
3924: == NULL)
3925: {
3926: (*s_etat_processus).erreur_systeme =
3927: d_es_allocation_memoire;
3928: return;
3929: }
3930:
3931: if (((*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3932: .suivant).donnee = allocation(s_etat_processus, INT))
3933: == NULL)
3934: {
3935: (*s_etat_processus).erreur_systeme =
3936: d_es_allocation_memoire;
3937: return;
3938: }
3939:
3940: (*((integer8 *) (*(*(*((struct_liste_chainee *)
3941: (*s_objet_adresse).objet)).suivant).donnee).objet)) =
3942: (integer8) ntohs(adresse_ipv6.sin6_port);
3943:
3944: (*(*((struct_liste_chainee *) (*s_objet_adresse).objet))
3945: .suivant).suivant = NULL;
3946: # else
3947: if ((*s_etat_processus).langue == 'F')
3948: {
3949: printf("+++Attention : Support du protocole"
3950: " IPv6 indisponible\n");
3951: }
3952: else
3953: {
3954: printf("+++Warning : IPv6 support "
3955: "unavailable\n");
3956: }
3957: # endif
3958: }
3959: else
3960: {
3961: longueur_adresse = 0;
3962: recvfrom((*((struct_socket *)
3963: (*s_objet_argument_1).objet)).socket, tampon_lecture,
3964: position_finale, MSG_DONTWAIT,
3965: NULL, &longueur_adresse);
3966: }
3967:
3968: free(tampon_lecture);
3969:
3970: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3971: s_objet_resultat) == d_erreur)
3972: {
3973: return;
3974: }
1.73 bertrand 3975: #endif
1.1 bertrand 3976: }
3977: }
3978: else
3979: {
3980: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3981: return;
3982: }
3983:
1.6 bertrand 3984: liberation(s_etat_processus, s_objet_argument_1);
1.1 bertrand 3985:
3986: return;
3987: }
3988:
3989: // vim: ts=4