[exim-cvs] Code tidying

Página Principal
Apagar esta mensagem
Responder a esta mensagem
Autor: Exim Git Commits Mailing List
Data:  
Para: exim-cvs
Assunto: [exim-cvs] Code tidying
Gitweb: http://git.exim.org/exim.git/commitdiff/a56cc2b8851e3c076eb064712249aee81a08ef87
Commit:     a56cc2b8851e3c076eb064712249aee81a08ef87
Parent:     ddcf2b5f0a330c6281d7d1e337d95c6123ec267a
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Thu Nov 27 16:28:03 2014 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Mon Jan 12 18:58:34 2015 +0000


    Code tidying
---
 src/src/functions.h |    2 +-
 src/src/ip.c        |   10 ++++----
 src/src/spam.c      |   61 ++++++++++++++++++++++++++++----------------------
 3 files changed, 40 insertions(+), 33 deletions(-)


diff --git a/src/src/functions.h b/src/src/functions.h
index 68609f2..3476725 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -204,7 +204,7 @@ extern int     host_scan_for_local_hosts(host_item *, host_item **, BOOL *);


 extern void    invert_address(uschar *, uschar *);
 extern int     ip_bind(int, int, uschar *, int);
-extern int     ip_connect(int, int, uschar *, int, int);
+extern int     ip_connect(int, int, const uschar *, int, int);
 extern int     ip_connectedsocket(int, const uschar *, int, int,
                  int, host_item *, uschar **);
 extern int     ip_get_address_family(int);
diff --git a/src/src/ip.c b/src/src/ip.c
index ca5ca9b..ec034ab 100644
--- a/src/src/ip.c
+++ b/src/src/ip.c
@@ -64,11 +64,11 @@ Returns:      nothing - failure provokes a panic-die
 */


static void
-ip_addrinfo(uschar *address, struct sockaddr_in6 *saddr)
+ip_addrinfo(const uschar *address, struct sockaddr_in6 *saddr)
{
#ifdef IPV6_USE_INET_PTON

-  if (inet_pton(AF_INET6, CS address, &saddr->sin6_addr) != 1)
+  if (inet_pton(AF_INET6, CCS address, &saddr->sin6_addr) != 1)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "unable to parse \"%s\" as an "
       "IP address", address);
   saddr->sin6_family = AF_INET6;
@@ -81,7 +81,7 @@ ip_addrinfo(uschar *address, struct sockaddr_in6 *saddr)
   hints.ai_family = AF_INET6;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags = AI_NUMERICHOST;
-  if ((rc = getaddrinfo(CS address, NULL, &hints, &res)) != 0 || res == NULL)
+  if ((rc = getaddrinfo(CCS address, NULL, &hints, &res)) != 0 || res == NULL)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "unable to parse \"%s\" as an "
       "IP address: %s", address,
       (rc == 0)? "NULL result returned" : gai_strerror(rc));
@@ -178,7 +178,7 @@ Returns:      0 on success; -1 on failure, with errno set
 */


int
-ip_connect(int sock, int af, uschar *address, int port, int timeout)
+ip_connect(int sock, int af, const uschar *address, int port, int timeout)
{
struct sockaddr_in s_in4;
struct sockaddr *s_ptr;
@@ -208,7 +208,7 @@ IPv6 support. */
memset(&s_in4, 0, sizeof(s_in4));
s_in4.sin_family = AF_INET;
s_in4.sin_port = htons(port);
- s_in4.sin_addr.s_addr = (S_ADDR_TYPE)inet_addr(CS address);
+ s_in4.sin_addr.s_addr = (S_ADDR_TYPE)inet_addr(CCS address);
s_ptr = (struct sockaddr *)&s_in4;
s_len = sizeof(s_in4);
}
diff --git a/src/src/spam.c b/src/src/spam.c
index 6458a4a..ec0ae93 100644
--- a/src/src/spam.c
+++ b/src/src/spam.c
@@ -48,6 +48,7 @@ spam(uschar **listptr)
fd_set select_fd;
#endif
uschar *spamd_address_work;
+ static const char * loglabel = US"spam acl condition:";

   /* stop compiler warning */
   result = 0;
@@ -78,7 +79,8 @@ spam(uschar **listptr)
     if (spamd_address_work == NULL)
       {
       log_write(0, LOG_MAIN|LOG_PANIC,
-        "spamassassin acl condition: spamd_address starts with $, but expansion failed: %s", expand_string_message);
+        "%s spamd_address starts with $, but expansion failed: %s",
+    loglabel, expand_string_message);
       return DEFER;
       }
     }
@@ -106,7 +108,7 @@ spam(uschar **listptr)
     {
     /* error while spooling */
     log_write(0, LOG_MAIN|LOG_PANIC,
-           "spam acl condition: error while creating mbox spool file");
+           "%s error while creating mbox spool file", loglabel);
     return DEFER;
     }


@@ -137,12 +139,13 @@ spam(uschar **listptr)
       if (sscanf(CS address, "%23s %u", this_spamd->tcp_addr, &(this_spamd->tcp_port)) != 2)
         {
         log_write(0, LOG_MAIN,
-          "spam acl condition: warning - invalid spamd address: '%s'", address);
+          "%s warning - invalid spamd address: '%s'", loglabel, address);
         continue;
     }


       spamd_address_vector[num_servers] = this_spamd;
-      if (++num_servers > 31)
+      if (  ++num_servers
+     >= sizeof(spamd_address_vector)/sizeof(spamd_address_vector[0]))
         break;
       }


@@ -150,41 +153,43 @@ spam(uschar **listptr)
     if (!num_servers)
       {
       log_write(0, LOG_MAIN|LOG_PANIC,
-         "spam acl condition: no useable spamd server addresses in spamd_address configuration option.");
+         "%s no useable spamd server addresses in spamd_address configuration option.",
+     loglabel);
       (void)fclose(mbox_file);
       return DEFER;
       }


-    while ( num_servers > 0 )
+    while (num_servers > 0)
       {
       int i;


       /* Randomly pick a server to try */
-      current_server = random_number( num_servers );
+      current_server = random_number(num_servers);


       debug_printf("trying server %s, port %u\n",
                    spamd_address_vector[current_server]->tcp_addr,
                    spamd_address_vector[current_server]->tcp_port);


       /* contact a spamd */
-      if ( (spamd_sock = ip_socket(SOCK_STREAM, AF_INET)) < 0)
+      if ((spamd_sock = ip_socket(SOCK_STREAM, AF_INET)) < 0)
     {
         log_write(0, LOG_MAIN|LOG_PANIC,
-           "spam acl condition: error creating IP socket for spamd");
+           "%s error creating IP socket for spamd", loglabel);
         (void)fclose(mbox_file);
         return DEFER;
     }


-      if (ip_connect( spamd_sock,
-                      AF_INET,
-                      spamd_address_vector[current_server]->tcp_addr,
-                      spamd_address_vector[current_server]->tcp_port,
-                      5 ) > -1)
+      if (ip_connect(spamd_sock,
+                     AF_INET,
+                     spamd_address_vector[current_server]->tcp_addr,
+                     spamd_address_vector[current_server]->tcp_port,
+                     5 ) > -1)
         /* connection OK */
         break;


       log_write(0, LOG_MAIN|LOG_PANIC,
-         "spam acl condition: warning - spamd connection to %s, port %u failed: %s",
+         "%s warning - spamd connection to %s, port %u failed: %s",
+     loglabel,
          spamd_address_vector[current_server]->tcp_addr,
          spamd_address_vector[current_server]->tcp_port,
          strerror(errno));
@@ -193,13 +198,13 @@ spam(uschar **listptr)


       /* Remove the server from the list. XXX We should free the memory */
       num_servers--;
-      for ( i = current_server; i < num_servers; i++ )
+      for (i = current_server; i < num_servers; i++)
         spamd_address_vector[i] = spamd_address_vector[i+1];
       }


-    if ( num_servers == 0 )
+    if (num_servers == 0)
       {
-      log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
+      log_write(0, LOG_MAIN|LOG_PANIC, "%s all spamd servers failed", loglabel);
       (void)fclose(mbox_file);
       return DEFER;
       }
@@ -211,7 +216,8 @@ spam(uschar **listptr)
     if ((spamd_sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
       {
       log_write(0, LOG_MAIN|LOG_PANIC,
-                "malware acl condition: spamd: unable to acquire socket (%s)",
+                "%s spamd: unable to acquire socket (%s)",
+        loglabel,
                 strerror(errno));
       (void)fclose(mbox_file);
       return DEFER;
@@ -223,7 +229,8 @@ spam(uschar **listptr)
     if (connect(spamd_sock, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0)
       {
       log_write(0, LOG_MAIN|LOG_PANIC,
-                "malware acl condition: spamd: unable to connect to UNIX socket %s (%s)",
+                "%s spamd: unable to connect to UNIX socket %s (%s)",
+        loglabel,
                 spamd_address_work, strerror(errno) );
       (void)fclose(mbox_file);
       (void)close(spamd_sock);
@@ -252,7 +259,7 @@ spam(uschar **listptr)
     {
     (void)close(spamd_sock);
     log_write(0, LOG_MAIN|LOG_PANIC,
-         "spam acl condition: spamd send failed: %s", strerror(errno));
+         "%s spamd send failed: %s", loglabel, strerror(errno));
     (void)fclose(mbox_file);
     (void)close(spamd_sock);
     return DEFER;
@@ -299,13 +306,13 @@ again:
     {
         if (result == -1)
           log_write(0, LOG_MAIN|LOG_PANIC,
-            "spam acl condition: %s on spamd socket", strerror(errno));
+            "%s %s on spamd socket", loglabel, strerror(errno));
         else
       {
           if (time(NULL) - start < SPAMD_TIMEOUT)
             goto again;
           log_write(0, LOG_MAIN|LOG_PANIC,
-            "spam acl condition: timed out writing spamd socket");
+            "%s timed out writing spamd socket", loglabel);
       }
         (void)close(spamd_sock);
         (void)fclose(mbox_file);
@@ -316,7 +323,7 @@ again:
       if (wrote == -1)
     {
     log_write(0, LOG_MAIN|LOG_PANIC,
-            "spam acl condition: %s on spamd socket", strerror(errno));
+            "%s %s on spamd socket", loglabel, strerror(errno));
         (void)close(spamd_sock);
         (void)fclose(mbox_file);
         return DEFER;
@@ -333,7 +340,7 @@ again:
   if (ferror(mbox_file))
     {
     log_write(0, LOG_MAIN|LOG_PANIC,
-      "spam acl condition: error reading spool file: %s", strerror(errno));
+      "%s error reading spool file: %s", loglabel, strerror(errno));
     (void)close(spamd_sock);
     (void)fclose(mbox_file);
     return DEFER;
@@ -358,7 +365,7 @@ again:
   if (i <= 0 && errno != 0)
     {
     log_write(0, LOG_MAIN|LOG_PANIC,
-         "spam acl condition: error reading from spamd socket: %s", strerror(errno));
+         "%s error reading from spamd socket: %s", loglabel, strerror(errno));
     (void)close(spamd_sock);
     return DEFER;
     }
@@ -380,7 +387,7 @@ again:
         &spamd_report_offset) != 3 )
       {
       log_write(0, LOG_MAIN|LOG_PANIC,
-         "spam acl condition: cannot parse spamd output");
+         "%s cannot parse spamd output", loglabel);
       return DEFER;
       }
     }