fin du TD2

This commit is contained in:
2025-09-15 17:35:35 +02:00
parent f09be2ba12
commit 933c5f5075
4 changed files with 762 additions and 0 deletions

View File

@@ -0,0 +1,241 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0" version="28.2.1">
<diagram name="Page-1" id="XiSRokyMfcDqU8OpTp_v">
<mxGraphModel dx="1188" dy="667" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="UyWOW2ZmnQcjWoapqL1b-15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-1" target="UyWOW2ZmnQcjWoapqL1b-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-1" value="début" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="350" y="60" width="120" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-2" target="UyWOW2ZmnQcjWoapqL1b-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-17" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-2" target="UyWOW2ZmnQcjWoapqL1b-56">
<mxGeometry relative="1" as="geometry">
<mxPoint x="630" y="260" as="targetPoint" />
<Array as="points">
<mxPoint x="630" y="220" />
<mxPoint x="630" y="260" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-2" value="p_reg == null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="370" y="180" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-18" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-3" target="UyWOW2ZmnQcjWoapqL1b-13">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-19" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-3" target="UyWOW2ZmnQcjWoapqL1b-57">
<mxGeometry relative="1" as="geometry">
<mxPoint x="540" y="430" as="targetPoint" />
<Array as="points">
<mxPoint x="635" y="340" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-3" value="fd == null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="370" y="300" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-22" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-5" target="UyWOW2ZmnQcjWoapqL1b-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-23" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-5" target="UyWOW2ZmnQcjWoapqL1b-58">
<mxGeometry relative="1" as="geometry">
<mxPoint x="410" y="640" as="targetPoint" />
<Array as="points">
<mxPoint x="520" y="600" />
<mxPoint x="645" y="600" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-5" value="p_reg != null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="480" y="510" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-24" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-6" target="UyWOW2ZmnQcjWoapqL1b-7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-25" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-6" target="UyWOW2ZmnQcjWoapqL1b-59">
<mxGeometry relative="1" as="geometry">
<mxPoint x="520" y="760" as="targetPoint" />
<Array as="points">
<mxPoint x="521" y="680" />
<mxPoint x="521" y="720" />
<mxPoint x="655" y="720" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-6" value="pmatch == null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="370" y="640" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-32" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-7" target="UyWOW2ZmnQcjWoapqL1b-9">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="160" y="1270" />
<mxPoint x="410" y="1270" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-63" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-7" target="UyWOW2ZmnQcjWoapqL1b-12">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-7" value="getline(&amp;amp;read_line, &amp;amp;n, fd) != -1" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="350" y="745" width="120" height="120" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-34" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-9" target="UyWOW2ZmnQcjWoapqL1b-14">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-35" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-9" target="UyWOW2ZmnQcjWoapqL1b-14">
<mxGeometry relative="1" as="geometry">
<mxPoint x="530" y="1480" as="targetPoint" />
<Array as="points">
<mxPoint x="531" y="1380" />
<mxPoint x="531" y="1480" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-9" value="read_line != null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="370" y="1340" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-10">
<mxGeometry relative="1" as="geometry">
<mxPoint x="570" y="1340" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-31" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-10">
<mxGeometry relative="1" as="geometry">
<mxPoint x="511" y="1340" as="targetPoint" />
<Array as="points">
<mxPoint x="510" y="1150" />
<mxPoint x="511" y="1150" />
<mxPoint x="511" y="1170" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-10" value="ping == null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="1160" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-28" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-11" target="UyWOW2ZmnQcjWoapqL1b-7">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="220" y="1075" />
<mxPoint x="220" y="740" />
<mxPoint x="410" y="740" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-11" value="regexec(p_reg, read_line, match, pmatch, 0) == 0" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="350" y="1010" width="120" height="130" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-26" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-12" target="UyWOW2ZmnQcjWoapqL1b-11">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-27" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-12" target="UyWOW2ZmnQcjWoapqL1b-9">
<mxGeometry relative="1" as="geometry">
<mxPoint x="590" y="1340" as="targetPoint" />
<Array as="points">
<mxPoint x="590" y="930" />
<mxPoint x="590" y="1340" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-12" value="read_line == null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="370" y="890" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-20" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-13" target="UyWOW2ZmnQcjWoapqL1b-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-13" target="UyWOW2ZmnQcjWoapqL1b-5">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-13" value="regcomp(p_reg, &quot;time=(.*) ms&quot;, REG_EXTENDED) != 0" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="370" y="430" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-14" value="fin" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="350" y="1480" width="120" height="80" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-36" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="450" y="200" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-37" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="310" y="1050" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-38" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="460" y="910" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-39" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="440" y="660" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-40" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="580" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-41" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="450" y="450" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-42" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="440" y="320" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-43" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="310" y="780" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-45" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="540" y="1170" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-46" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="445" y="1360" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-47" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="405" y="250" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-48" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="405" y="970" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-49" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="405" y="710" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-50" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="445" y="530" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-51" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="405" y="510" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-52" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="405" y="380" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-53" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="405" y="1410" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-55" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="500" y="1240" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-56" value="return ping" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="590" y="260" width="90" height="40" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-57" value="return ping" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="590" y="410" width="90" height="40" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-58" value="return ping" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="600" y="620" width="90" height="40" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-59" value="return ping" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="610" y="760" width="90" height="40" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-62" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="UyWOW2ZmnQcjWoapqL1b-11">
<mxGeometry relative="1" as="geometry">
<mxPoint x="510" y="1160" as="targetPoint" />
<mxPoint x="470" y="1075" as="sourcePoint" />
<Array as="points" />
</mxGeometry>
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-44" value="oui" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="480" y="1050" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="UyWOW2ZmnQcjWoapqL1b-64" value="&lt;div&gt;non&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="410" y="860" width="40" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@@ -0,0 +1,216 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0" version="28.2.1">
<diagram name="Page-1" id="M8LVymB8HHq2TiQXmYts">
<mxGraphModel dx="1678" dy="941" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="9-hR2cceIFRA6d9v-VIj-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-1" target="9-hR2cceIFRA6d9v-VIj-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-1" value="début" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="380" y="10" width="120" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-2" target="9-hR2cceIFRA6d9v-VIj-51">
<mxGeometry relative="1" as="geometry">
<Array as="points" />
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-2" target="9-hR2cceIFRA6d9v-VIj-26">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-2" value="fd != null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="400" y="120" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-17" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-3" target="9-hR2cceIFRA6d9v-VIj-5">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-56" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-3" target="9-hR2cceIFRA6d9v-VIj-51">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="210" as="targetPoint" />
<Array as="points">
<mxPoint x="360" y="470" />
<mxPoint x="360" y="471" />
<mxPoint x="250" y="471" />
<mxPoint x="250" y="180" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-3" value="strcmp(read_line, &quot;LOSS&quot;) == 0" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="430" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-19" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-4" target="9-hR2cceIFRA6d9v-VIj-8">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-20" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-4" target="9-hR2cceIFRA6d9v-VIj-8">
<mxGeometry relative="1" as="geometry">
<mxPoint x="610" y="840" as="targetPoint" />
<Array as="points">
<mxPoint x="611" y="740" />
<mxPoint x="611" y="840" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-4" value="ping &amp;gt; max" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="700" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-18" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-5" target="9-hR2cceIFRA6d9v-VIj-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-55" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-5" target="9-hR2cceIFRA6d9v-VIj-51">
<mxGeometry relative="1" as="geometry">
<mxPoint x="150" y="220" as="targetPoint" />
<Array as="points">
<mxPoint x="315" y="600" />
<mxPoint x="315" y="601" />
<mxPoint x="180" y="601" />
<mxPoint x="180" y="180" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-5" value="ping &amp;lt; 0.1" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="560" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-23" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-7" target="9-hR2cceIFRA6d9v-VIj-51">
<mxGeometry relative="1" as="geometry">
<mxPoint x="130" y="290" as="targetPoint" />
<Array as="points">
<mxPoint x="510" y="1090" />
<mxPoint x="511" y="1090" />
<mxPoint x="511" y="1110" />
<mxPoint x="100" y="1110" />
<mxPoint x="100" y="180" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-54" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-7" target="9-hR2cceIFRA6d9v-VIj-51">
<mxGeometry relative="1" as="geometry">
<mxPoint x="50" y="190" as="targetPoint" />
<Array as="points">
<mxPoint x="631" y="1020" />
<mxPoint x="631" y="1150" />
<mxPoint x="70" y="1150" />
<mxPoint x="70" y="180" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-7" value="ping &amp;gt; 100.0" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="1000" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-8" target="9-hR2cceIFRA6d9v-VIj-7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-22" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-8" target="9-hR2cceIFRA6d9v-VIj-7">
<mxGeometry relative="1" as="geometry">
<mxPoint x="610" y="980" as="targetPoint" />
<Array as="points">
<mxPoint x="611" y="880" />
<mxPoint x="611" y="980" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-8" value="ping &amp;lt; min" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="840" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-9" target="9-hR2cceIFRA6d9v-VIj-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-9" target="9-hR2cceIFRA6d9v-VIj-10">
<mxGeometry relative="1" as="geometry">
<mxPoint x="920" y="1240" as="targetPoint" />
<Array as="points">
<mxPoint x="921" y="340" />
<mxPoint x="921" y="1240" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-9" value="read_line == null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="300" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-27" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-10" target="9-hR2cceIFRA6d9v-VIj-26">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-28" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-10" target="9-hR2cceIFRA6d9v-VIj-26">
<mxGeometry relative="1" as="geometry">
<mxPoint x="630" y="1440" as="targetPoint" />
<Array as="points">
<mxPoint x="631" y="1280" />
<mxPoint x="631" y="1440" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-10" value="read_line != null" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="470" y="1240" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-26" value="fin" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="380" y="1440" width="120" height="80" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-30" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="540" y="720" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-31" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="910" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-32" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="360" y="570" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-33" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="350" y="440" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-34" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="550" y="320" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-35" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="470" y="130" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-39" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="650" y="180" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-40" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="550" y="1000" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-41" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="540" y="860" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-42" value="&lt;div&gt;oui&lt;/div&gt;" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="540" y="1260" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-43" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="770" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-44" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="630" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-45" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="500" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-46" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="390" y="260" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-47" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="370" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-48" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="1310" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-50" value="non" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="510" y="1050" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-52" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-51" target="9-hR2cceIFRA6d9v-VIj-9">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-53" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="9-hR2cceIFRA6d9v-VIj-51" target="9-hR2cceIFRA6d9v-VIj-10">
<mxGeometry relative="1" as="geometry">
<mxPoint x="1030" y="1250" as="targetPoint" />
<Array as="points">
<mxPoint x="1031" y="220" />
<mxPoint x="1031" y="1240" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="9-hR2cceIFRA6d9v-VIj-51" value="getline(&amp;amp;read_line, &amp;amp;n, fd) != -1" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="500" y="180" width="80" height="80" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

44
Compte_Rendu.md Normal file
View File

@@ -0,0 +1,44 @@
## Nombre de complexité selon le fichier
# daemon.c
create_daemon = 5
ping_request = 2
send_check = 4
check_keep_working = 4
daemon_work = 3
# db-sqlite.c
db_connect = 1
db_disconnect = 1
insert_hourly_report = 1
# ping-report
main = 4
# stats.c
get_ping_from_temp_log = 14
write_ping_log = 5
set_stats_ping = 11
# utils.c
write_pid_file = 2
remove_file = 1
## Algorythme des fonction avec une complexité supérieur ou égale à 6
voir sur draw.io avec les fichiers.
## Optimisation du code sur la complexité cyclomatique
Le résultat de cet exercice se trouve dans le fichier stats_corrigé.c
# get_ping_from_temp_log
Pour cela on a factoriser la partie avec le while dans la fonction get_ping_from_temp_log_correction.
# set_stats_ping
Pour cela on a factoriser la partie ou l'on regarde la marge dans lequel se trouve ping dans la fonction set_stats_ping_correction.

261
stats_corrigé.c Normal file
View File

@@ -0,0 +1,261 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <regex.h>
#include "../include/utils.h"
#include "../include/stats.h"
#include "../include/db-sqlite.h"
void get_ping_from_temp_log(char* read_line, size_t n, FILE* fd,
regex_t* p_reg, regmatch_t* pmatch, size_t nmatch, char* ping,
int start, int end, size_t size_ping){
/* Read file */
while(getline(&read_line,&n,fd) != -1){
if(read_line == NULL){
break;
}
/* Exec regex to find ping */
if(regexec(p_reg,read_line,nmatch,pmatch,0) == 0){
/* Extract ping position from read line */
start = (int) pmatch[1].rm_so;
end = (int) pmatch[1].rm_eo;
size_ping = (size_t) (end - start);
/* ping string memory allocation */
ping = malloc(sizeof(char) * (size_ping+2));
if(ping == NULL){
free(read_line);
read_line = NULL;
n = 0;
break;
}
/* Create ping string */
(void) strncpy(ping, &read_line[start], size_ping);
ping[size_ping]='\n';
ping[size_ping+1]='\0';
/* Free memory */
free(read_line);
read_line = NULL;
n = 0;
break;
}
free(read_line);
read_line = NULL;
n = 0;
}
}
/*
-- get_ping_from_temp_log --
Desc :
Function which get the ping from a temp log containing the last ping did by the program
In-param :
None
Out-param :
None
Return value :
Ping value as a string or NULL if an error occured
*/
/*@null@*/char* get_ping_from_temp_log(){
/* Variables */
FILE* fd = NULL;
char* read_line = NULL;
size_t n = 0;
size_t nmatch = 2;
regex_t *p_reg;
regmatch_t* pmatch;
char* ping = NULL;
int start;
int end;
size_t size_ping;
/* regex struct memory allocation */
p_reg = (regex_t *) malloc(sizeof(*p_reg));
if(p_reg == NULL){
return ping; /* NULL */
}
/* Open ping log file */
fd = fopen("/var/log/ping-report/last-ping.log","r");
if(fd == NULL){
free(p_reg);
return ping; /* NULL */
}
/* Construct regex to get ping from log file */
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
if(p_reg != NULL){
free(p_reg);
}
(void) fclose(fd);
return ping; /* NULL */
}
/* match info memory allocation */
pmatch = malloc(sizeof(*pmatch) * nmatch);
if(pmatch == NULL){
(void) fclose(fd);
regfree(p_reg);
free(p_reg);
return ping; /* NULL */
}
get_ping_from_temp_log(&read_line, &n, &fd,
&p_reg, &pmatch, nmatch, &ping,
start, end, size_ping);
/* free allocated memory */
regfree(p_reg);
free(p_reg);
free(pmatch);
if(read_line != NULL){
free(read_line);
}
(void) fclose(fd);
/* ping may be null, then it must mean that the ping request was lost */
return ping;
}
/*
-- write_ping_log --
Desc :
Function which write a given ping in log file
In-param :
new_ping : string value of a ping
Out-param :
None
Return value :
None
*/
void write_ping_log(char* new_ping){
/* Variables */
FILE* fd;
/* Open log file */
fd = fopen("/var/log/ping-report/all-ping.log","a+");
if(fd != NULL){
if(new_ping == NULL){
new_ping = (char *) malloc(5*sizeof(char));
if(new_ping == NULL){
(void) fclose(fd);
return;
}
(void) snprintf(new_ping,5*sizeof(char),"LOSS");
}
(void) fwrite(new_ping, sizeof(char), strlen(new_ping), fd);
(void) fclose(fd);
}else{
perror("write ping : ");
}
free(new_ping);
}
void set_stats_ping_correction(int ping, int* max, int* min, int* nb_high){
/* Max ping */
if(ping > max){
max = ping;
}
/* Min ping */
if(ping < min){
min = ping;
}
/* Number of ping above 100 ms */
if(ping > 100.0){
nb_high++;
}
}
/*
-- set_stats_ping --
Desc :
Function which calculate statistics about ping values, from log file.
In-param :
None
Out-param :
None
Return value :
None
*/
void set_stats_ping(){
/* Variables */
FILE* fd;
/* Open log file */
fd = fopen("/var/log/ping-report/all-ping.log","r");
if(fd != NULL){
/* Stats variables */
double ping = 0.0;
double sum = 0.0;
double max = 0.0;
double min = 100.0;
double mean = 0.0;
int nb_high = 0;
int nb_loss = 0;
int nb_ping = 0;
char* read_line = NULL;
size_t n = 0;
/* Read file */
while(getline(&read_line,&n,fd) != -1){
/* Check getline error */
if(read_line == NULL){
break;
}
/* Check if the ping is flagged as LOSS */
if(strcmp(read_line,"LOSS") == 0){
nb_loss++;
}else{
/* Evaluate the ping as a double */
ping = strtod(read_line,NULL);
/* Test null ping */
if(ping < 0.1){
/* Ignore null ping */
}else{
/* Number of ping readed (for mean calculation) */
nb_ping++;
set_stats_ping_correction(ping, &max, &min, &nb_high);
/* Sum (for mean calculation) */
sum += ping;
}
}
free(read_line);
n = 0;
}
/* Mean calculation */
mean = sum / (double) nb_ping;
(void) fclose(fd);
insert_hourly_report(mean,max,min,nb_high,nb_loss,nb_ping);
if(read_line != NULL){
free(read_line);
}
}else{
perror("stats : ");
}
}