This commit is contained in:
2025-09-15 17:44:47 +02:00
parent f09be2ba12
commit db41c94d58
6 changed files with 96 additions and 40 deletions

33
TP2.txt Normal file
View File

@@ -0,0 +1,33 @@
TP2 David AKAGUNDUZ Bamba TOP
Nous allons analyser lesfichier et trouver leur nombre de compléxité cyclonique :
Fichier daemon.c :
Fonction create_deamon : 4
Fonction ping_request : 2
Fonction send_check : 4
Fonction check_keep_working : 4
Fonction daemon_work : 3
Fichier db-sqlite.c :
Fonction db_connect : 1
Fonction db_disconnect : 1
Fonction insert_hourly_report : 1
Fichier ping-report.c :
Focntion main : 4
Fichier stats.c :
Fonction get_ping_from_temp_log : 15
Fonction write_ping_log : 5
Fonction set_stats_ping : 17
Fichier utils.c :
Fonction write_pid_file : 2
Fonction remove_file : 1

BIN
get_ping_from_temp_log.pdf Normal file

Binary file not shown.

BIN
ping-report/ping-report Executable file

Binary file not shown.

BIN
ping-report/ping-report.db Normal file

Binary file not shown.

View File

@@ -22,6 +22,59 @@
Return value : Return value :
Ping value as a string or NULL if an error occured Ping value as a string or NULL if an error occured
*/ */
void whil(FILE* fd,
char* read_line,
size_t n ,
size_t nmatch,
regex_t *p_reg,
regmatch_t* pmatch,
char* ping,
int start,
int end,
size_t size_ping){
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;
}
}
/*@null@*/char* get_ping_from_temp_log(){ /*@null@*/char* get_ping_from_temp_log(){
/* Variables */ /* Variables */
@@ -68,46 +121,16 @@
} }
/* Read file */ /* Read file */
while(getline(&read_line,&n,fd) != -1){ whil(FILE* fd,
char* read_line,
if(read_line == NULL){ size_t n ,
break; size_t nmatch,
} regex_t *p_reg,
regmatch_t* pmatch,
/* Exec regex to find ping */ char* ping,
int start,
if(regexec(p_reg,read_line,nmatch,pmatch,0) == 0){ int end,
size_t size_ping);
/* 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;
}
/* free allocated memory */ /* free allocated memory */
regfree(p_reg); regfree(p_reg);

BIN
set_stats_ping.pdf Normal file

Binary file not shown.