diff --git a/TD2_Diagramme.pdf b/TD2_Diagramme.pdf new file mode 100644 index 0000000..8d4bad6 Binary files /dev/null and b/TD2_Diagramme.pdf differ diff --git a/Untitled Diagram.drawio b/Untitled Diagram.drawio new file mode 100644 index 0000000..b289335 --- /dev/null +++ b/Untitled Diagram.drawio @@ -0,0 +1,733 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ping-report/src/stats copy.c b/ping-report/src/stats copy.c new file mode 100644 index 0000000..43d7873 --- /dev/null +++ b/ping-report/src/stats copy.c @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../include/utils.h" +#include "../include/stats.h" +#include "../include/db-sqlite.h" + +/* + -- 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 */ + } + + + + /* Read file */ + + whilegetline(getline(&read_line,&n,fd)) + + + /* free allocated memory */ + regfree(p_reg); + free(p_reg); + free(pmatch); + if(read_line != NULL){ + free(read_line); + }c + + (void) fclose(fd); + + /* ping may be null, then it must mean that the ping request was lost */ + return ping; +} + +void whilegetline( int gegetline) { + while ( gegetline =! -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_egetlineo; + 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; + } + +} \ No newline at end of file diff --git a/ping-report/src/stats.c b/ping-report/src/stats.c index 5b343e8..882668c 100644 --- a/ping-report/src/stats.c +++ b/ping-report/src/stats.c @@ -115,7 +115,7 @@ free(pmatch); if(read_line != NULL){ free(read_line); - } + }c (void) fclose(fd);