: nply/fiche2

commit 7a2b8b18883c8685015afa6f9450e9c09c7b9f2a
parent 89c5fc86805c394313f3f6bdc06b15d18324b33e
Author: Björn Ketelaars <bjorn.ketelaars@hydroxide.nl>
Date: Fri, 4 Sep 2015 11:59:44 +0200

wrap printf in info() and replace a couple of printf statements
2 files changed, 21 insertions(+), 15 deletions(-)
M
fiche.c
|
35
++++++++++++++++++++---------------
M
fiche.h
|
1
+
diff --git a/fiche.c b/fiche.c
@@ -134,7 +134,7 @@ void perform_connection(int listen_socket)
 
 void display_date()
 {
-    printf("%s\n", get_date());
+    info("%s\n", get_date());
 }
 
 char *get_date()

@@ -160,7 +160,7 @@ struct client_data get_client_address(struct sockaddr_in client_address)
     hostp = gethostbyaddr((const char *)&client_address.sin_addr.s_addr, sizeof(client_address.sin_addr.s_addr), AF_INET);
     if (hostp == NULL)
     {
-        printf("ERROR: Couldn't obtain client's hostname\n");
+        info("ERROR: Couldn't obtain client's hostname\n");
         data.hostname = "n/a";
     }
     else

@@ -169,7 +169,7 @@ struct client_data get_client_address(struct sockaddr_in client_address)
     hostaddrp = inet_ntoa(client_address.sin_addr);
     if (hostaddrp == NULL)
     {
-        printf("ERROR: Couldn't obtain client's address\n");
+        info("ERROR: Couldn't obtain client's address\n");
         data.ip_address = "n/a";
     }
     else

@@ -199,11 +199,11 @@ void save_log(char *slug, char *hostaddrp, char *h_name)
 void display_info(struct client_data data, char *slug, char *message)
 {
     if (slug == NULL)
-        printf("%s\n", message);
-    else printf("Saved to: %s\n", slug);
+        info("%s\n", message);
+    else info("Saved to: %s\n", slug);
     display_date();
-    printf("Client: %s (%s)\n", data.ip_address, data.hostname);
-    printf("====================================\n");
+    info("Client: %s (%s)\n", data.ip_address, data.hostname);
+    info("====================================\n");
 }
 
 char *check_banlist(char *ip_address)

@@ -362,11 +362,16 @@ void set_basedir()
 
 void startup_message()
 {
-    printf("====================================\n");
-    printf("Domain name: %s\n", DOMAIN);
-    printf("Saving files to: %s\n", BASEDIR);
-    printf("Fiche started listening on port %d.\n", PORT);
-    printf("====================================\n");
+    info("====================================\n");
+    info("Domain name: %s\n", DOMAIN);
+    info("Saving files to: %s\n", BASEDIR);
+    info("Fiche started listening on port %d.\n", PORT);
+    info("====================================\n");
+}
+
+void info(char *buffer, ...)
+{
+    printf(buffer);
 }
 
 void parse_parameters(int argc, char **argv)

@@ -387,7 +392,7 @@ void parse_parameters(int argc, char **argv)
                 break;
             case 'B':
                 BUFSIZE = atoi(optarg);
-                printf("Buffer size set to: %d.\n", BUFSIZE);
+                info("Buffer size set to: %d.\n", BUFSIZE);
                 break;
             case 'b':
                 BANFILE = optarg;

@@ -395,14 +400,14 @@ void parse_parameters(int argc, char **argv)
                 break;
             case 's':
                 SLUG_SIZE = atoi(optarg);
-                printf("Slug size set to: %d.\n", SLUG_SIZE);
+                info("Slug size set to: %d.\n", SLUG_SIZE);
                 break;
             case 'o':
                 BASEDIR = optarg;
                 break;
             case 'l':
                 LOG = optarg;
-                printf("Log file: %s\n", LOG);
+                info("Log file: %s\n", LOG);
                 break;
             case 'u':
                 set_uid_gid(optarg);
diff --git a/fiche.h b/fiche.h
@@ -90,6 +90,7 @@ void parse_parameters(int argc, char **argv);
 void save_log(char *slug, char *hostaddrp, char *h_name);
 void change_owner(char *directory);
 void set_uid_gid();
+void info(char *buffer, ...);
 
 char *check_banlist(char *ip_address);
 char *check_whitelist(char *ip_address);