Compare commits

...

6 Commits
main ... main

Author SHA1 Message Date
2cdf49fb6f compte rendu 2024-09-17 12:21:38 +02:00
7949ba7f52 compte rendu 2024-09-17 12:20:40 +02:00
eeb103dace compte rendu 2024-09-17 10:42:40 +02:00
17f5d95148 compte rendu 2024-09-17 10:42:05 +02:00
0ce3f8d77c compte rendu 2024-09-17 10:40:58 +02:00
4fb2808ce3 compte rendu 2024-09-17 10:39:28 +02:00
2 changed files with 96 additions and 23 deletions

View File

@ -0,0 +1,62 @@
# COMPTE RENDU
## Fait par VALLAT Guillaume et GENIQUE Florian
## Calculer la complexité cyclomatique du code donnée
### 1. daemon.c :
* create_daemon() : 4 complexité cyclomatique
* ping_request() : 2 complexité cyclomatique
* send_check() : 4 complexité cyclomatique
* check_keep_working() : 4 complexité cyclomatique
* daemon_work() : 3 complexité cyclomatique
### 2. db-sqlite.c :
* db_connect() : 1 complexité cyclomatique
* db_disconnect() : 1 complexité cyclomatique
* insert_hourly_report(): 1 complexité cyclomatique
### 3. ping-report.c :
* main() : 4 complexité cyclomatique
### 4. stats.C :
* get_ping_from_temp_log() : 13 complexité cyclomatique
* write_ping_log() : 4 complexité cyclomatiquue
* set_stats_ping() : 23 complexité cyclomatique
### 5. utils.c :
* write_pid_file() : 2 complexité cyclomatique
* remove_file() : 1 complexité cyclomatique
## DIAGRAMMES
## OPTIMISATION DU CODE DE LA FONCTION get_ping_from_temp_log() :
ligne de 127 à 130 mis en commentaire
les if :
- if(p_reg == NULL)
- if(fd == NULL)
- if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0)
- if(pmatch == NULL)
on été décaler dans une fonction a part appelé ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch) et nous retourne le ping ce qui nous rend a la fonction get_ping_from_temp_log et la nouvelle fonction crées à 5 complexité cyclomatique chacune.
## NOUVEAU DIAGRAMMES

View File

@ -22,6 +22,32 @@
Return value :
Ping value as a string or NULL if an error occured
*/
char* ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch){
char* ping = NULL;
if(p_reg == NULL){
return ping; /* NULL */
}
if(fd == NULL){
free(p_reg);
return ping; /* NULL */
}
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
//if(p_reg != NULL){
free(p_reg);
//}
(void) fclose(fd);
return ping; /* NULL */
}
if(pmatch == NULL){
(void) fclose(fd);
regfree(p_reg);
free(p_reg);
return ping; /* NULL */
}
return ping;
}
/*@null@*/char* get_ping_from_temp_log(){
/* Variables */
@ -38,34 +64,19 @@
/* 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 */
}
ping = ifFunct(fd, p_reg, pmatch);
/* Read file */
while(getline(&read_line,&n,fd) != -1){
@ -113,9 +124,9 @@
regfree(p_reg);
free(p_reg);
free(pmatch);
if(read_line != NULL){
free(read_line);
}
//if(read_line != NULL){
// free(read_line);
//}
(void) fclose(fd);