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