[pisa-src] r1357 - trunk/libpisa/log.c

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 27 Oct 2009 17:29:58 +0100

Author: tjansen
Date: Tue Oct 27 17:29:58 2009
New Revision: 1357

Log:
Cosmetics: Removed unnecessary curly braces.

Modified:
   trunk/libpisa/log.c

Modified: trunk/libpisa/log.c
==============================================================================
--- trunk/libpisa/log.c Tue Oct 27 17:24:16 2009        (r1356)
+++ trunk/libpisa/log.c Tue Oct 27 17:29:58 2009        (r1357)
@@ -42,8 +42,7 @@
 
        f = fopen(logfile, "a");
 
-       if (f == NULL)
-       {
+       if (f == NULL) {
                fprintf(stderr, "Error reading log file.\n");
                logfile[0] = '\0';
                return 0;
@@ -65,21 +64,21 @@
  */
 void log_start_connection(const char *hit, struct in_addr *address)
 {
-       if (logfile != NULL)
-       {
-               char buffer[LENGTH_DATE_BUFFER];
-               char ip_buffer[INET_ADDRSTRLEN];
+       char buffer[LENGTH_DATE_BUFFER];
+       char ip_buffer[INET_ADDRSTRLEN];
 
-               get_formatted_current_time(buffer, LENGTH_DATE_BUFFER, 
DATE_FORMAT);
+       if (logfile == NULL)
+               return;
 
-               LOG("New Connection: %s", buffer);
-               LOG("Hit: %s", hit);
+       get_formatted_current_time(buffer, LENGTH_DATE_BUFFER, DATE_FORMAT);
 
-               inet_ntop(AF_INET, address, ip_buffer, sizeof(ip_buffer));
-               LOG("IPv4: %s", ip_buffer);
+       LOG("New Connection: %s", buffer);
+       LOG("Hit: %s", hit);
 
-               log_nat_mapping_start(hit, address);
-       }
+       inet_ntop(AF_INET, address, ip_buffer, sizeof(ip_buffer));
+       LOG("IPv4: %s", ip_buffer);
+
+       log_nat_mapping_start(hit, address);
 }
 
 /**
@@ -90,27 +89,27 @@
  */
 void log_stop_connection(const char *hit, int number_of_bytes, time_t start)
 {
-       if (logfile != NULL)
-       {
-               char buffer[LENGTH_DATE_BUFFER];
-               time_t rawtime;
-               double dif;
-
-               time(&rawtime);
-               convert_time_t_to_formatted_string(&rawtime, buffer, 
LENGTH_DATE_BUFFER, DATE_FORMAT, 0);
-
-               LOG("End of Connection: %s", buffer);
-               LOG("Hit: %s", hit);
-               LOG("Number of Bytes transferred: %i", number_of_bytes);
-               // Calculate Connection Time
-               dif = difftime(rawtime, start);
-               rawtime = (time_t) dif;
-               convert_time_t_to_formatted_string(&rawtime, buffer, 
LENGTH_DATE_BUFFER, "%H:%M:%S", 1);
-               LOG("Connection length: %s", buffer);
+       char buffer[LENGTH_DATE_BUFFER];
+       time_t rawtime;
+       double dif;
 
-               log_month_connection(hit, number_of_bytes, rawtime);
-               log_nat_mapping_end(hit);
-       }
+       if (logfile == NULL)
+               return;
+
+       time(&rawtime);
+       convert_time_t_to_formatted_string(&rawtime, buffer, 
LENGTH_DATE_BUFFER, DATE_FORMAT, 0);
+
+       LOG("End of Connection: %s", buffer);
+       LOG("Hit: %s", hit);
+       LOG("Number of Bytes transferred: %i", number_of_bytes);
+       // Calculate Connection Time
+       dif = difftime(rawtime, start);
+       rawtime = (time_t) dif;
+       convert_time_t_to_formatted_string(&rawtime, buffer, 
LENGTH_DATE_BUFFER, "%H:%M:%S", 1);
+       LOG("Connection length: %s", buffer);
+
+       log_month_connection(hit, number_of_bytes, rawtime);
+       log_nat_mapping_end(hit);
 }
 
 /**
@@ -133,10 +132,8 @@
        old_values_available = read_old_month_values(path, 
&old_number_of_bytes, &old_connection_length);
 
        FILE* f = fopen(path, "w");
-       if (f != NULL)
-       {
-               if (old_values_available)
-               {
+       if (f != NULL) {
+               if (old_values_available) {
                        number_of_bytes += old_number_of_bytes;
                        length += old_connection_length;
                }
@@ -165,8 +162,7 @@
        inet_ntop(AF_INET, address, ip_buffer, sizeof(ip_buffer));
 
        FILE* f = fopen(path, "a");
-       if (f != NULL)
-       {
+       if (f != NULL) {
                fprintf(f, "Start: %s\n", buffer);
                fprintf(f, "%s\n", ip_buffer);
                fclose(f);
@@ -187,8 +183,7 @@
        get_nat_map_file_for_hit(path, hit);
 
        FILE* f = fopen(path, "a");
-       if (f != NULL)
-       {
+       if (f != NULL) {
                fprintf(f, "End: %s\n", buffer);
                fclose(f);
        }
@@ -199,14 +194,13 @@
  */
 void close_log(void)
 {
-       if (logfile != NULL)
-       {
-               char buffer[LENGTH_DATE_BUFFER];
+       char buffer[LENGTH_DATE_BUFFER];
 
-               get_formatted_current_time(buffer, LENGTH_DATE_BUFFER, 
DATE_FORMAT);
+       if (logfile == NULL)
+               return;
 
-               LOG("Logging End: %s", buffer);
-       }
+       get_formatted_current_time(buffer, LENGTH_DATE_BUFFER, DATE_FORMAT);
+       LOG("Logging End: %s", buffer);
 }
 
 /**
@@ -221,8 +215,7 @@
        strcpy(dst, hit);
 
        current = strchr(dst, ':');
-       while (current != NULL)
-       {
+       while (current != NULL) {
                strncpy(current, ".", 1);
                current = strchr(dst, ':');
        }
@@ -247,14 +240,10 @@
 
 
        if (fgets(buffer, MONTH_FILE_BUFFER_LENGTH, f) == NULL)
-       {
                return 0;
-       }
        *number_of_bytes = atoi(buffer);
        if (fgets(buffer, MONTH_FILE_BUFFER_LENGTH, f) == NULL)
-       {
                return 0;
-       }
        *length = (time_t)atoi(buffer);
 
        fclose(f);
@@ -325,31 +314,27 @@
 
        // Use local or gmtime
        if (!gm)
-       {
                ts = localtime(time);
-       }
        else
-       {
                ts = gmtime(time);
-       }
        return (strftime(buffer, buffer_size, time_format, ts) != 0);
 }
 
 void print_to_log(const char *fmt, ...)
 {
-       if (logfile != NULL)
-       {
-               va_list args;
-               va_start(args, fmt);
-
-               FILE *f = fopen(logfile, "a");
-
-               if (f != NULL)
-               {
-                       vfprintf(f, fmt, args);
-                       fclose(f);
-               }
+       va_list args;
+
+       if (logfile == NULL)
+               return;
+
+       va_start(args, fmt);
 
-               va_end(args);
+       FILE *f = fopen(logfile, "a");
+
+       if (f != NULL) {
+               vfprintf(f, fmt, args);
+               fclose(f);
        }
+
+       va_end(args);
 }

Other related posts:

  • » [pisa-src] r1357 - trunk/libpisa/log.c - Thomas Jansen