Compare commits

..

No commits in common. "main" and "main" have entirely different histories.
main ... main

6 changed files with 23 additions and 98 deletions

View File

@ -1,47 +0,0 @@
# Compte-rendu TP
###### Groupe SCHIED Killian, LANDRIN Dylan
## Fichier "deamon.c"
#### Détails
##### create_deamon()
Complexité Cyclomatique : 4
##### ping_request()
Complexité Cyclomatique : 2
##### send_check()
Complexité Cyclomatique : 4
##### check_keep_working()
Complexité Cyclomatique : 4
##### daemon_work()
Complexité Cyclomatique : 3
## Fichier "db-sqlite.c"
#### Détails
##### db_connect()
Complexité Cyclomatique : 1
##### db_disconnect()
Complexité Cyclomatique : 1
##### insert_hourly_report()
Complexité Cyclomatique : 1
## Fichier "ping-report.c"
#### Détails
##### main()
Complexité Cyclomatique : 4
## Fichier "stats.c"
### Avant modification
#### Détails
##### get_ping_from_temp_log()
Complexité Cyclomatique : 15
##### write_ping_log()
Complexité Cyclomatique : 4
##### set_stats_ping()
Complexité Cyclomatique : 25
### Après modification
#### Détails
##### get_ping_from_temp_log()
Complexité Cyclomatique : ?
##### set_stats_ping()
Complexité Cyclomatique : ?
## Fichier "utils.c"
#### Détails
##### write_pid_file()
Complexité Cyclomatique : 2
##### remove_file()
Complexité Cyclomatique : 1

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 317 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 481 KiB

Binary file not shown.

Binary file not shown.

View File

@ -32,6 +32,9 @@
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));
@ -48,9 +51,9 @@
/* Construct regex to get ping from log file */
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
//if(p_reg != NULL){
if(p_reg != NULL){
free(p_reg);
//}
}
(void) fclose(fd);
return ping; /* NULL */
}
@ -64,41 +67,6 @@
return ping; /* NULL */
}
ping = find_ping(read_line, n, fd);
/* 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;
}
/*
La fonction get_ping_from_temp_log avais une complexité cyclomatique de 15.
modifications:
ligne 51 et 53 (anciennement 54 et 56):
retirer la verification if, car peut importe ce qu'il se passe, p_reg ne peut pas être null, la fonction ce serait arretée
lignes 73,74 et 75 (anciennement 116, 117 et 118):
retirer encore du code mort, car la verification est innutil, avant de déplacer le while, read_line était forcemment nulll a ce moment.
Le while a é segmenter en une fonction find_ping() a part,qui prend en parametre ce dont il a besoin et retourne ping.
Tous ces changements on fait passer la complexité cyclomatique de get_ping_from_temp_log de 15, à 5. get_ping quand a lui est également à 5.
*/
char* find_ping(char* read_line, size_t n, FILE* fd){
int start;
int end;
size_t size_ping;
char* ping2 = NULL;
/* Read file */
while(getline(&read_line,&n,fd) != -1){
@ -116,8 +84,8 @@ char* find_ping(char* read_line, size_t n, FILE* fd){
size_ping = (size_t) (end - start);
/* ping string memory allocation */
ping2 = malloc(sizeof(char) * (size_ping+2));
if(ping2 == NULL){
ping = malloc(sizeof(char) * (size_ping+2));
if(ping == NULL){
free(read_line);
read_line = NULL;
n = 0;
@ -125,9 +93,9 @@ char* find_ping(char* read_line, size_t n, FILE* fd){
}
/* Create ping string */
(void) strncpy(ping2, &read_line[start], size_ping);
ping2[size_ping]='\n';
ping2[size_ping+1]='\0';
(void) strncpy(ping, &read_line[start], size_ping);
ping[size_ping]='\n';
ping[size_ping+1]='\0';
/* Free memory */
free(read_line);
@ -139,8 +107,20 @@ char* find_ping(char* read_line, size_t n, FILE* fd){
free(read_line);
read_line = NULL;
n = 0;
return ping2;
}
/* 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;
}
/*