]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conn.c
Don't define SSL_Want{Read|Write}() when SSL is disabled
[ngircd-alex.git] / src / ngircd / conn.c
index 324fa4219a9d204723572e1eeb8fbf8ea1badbee..fad3435734a932f2018b430d71ce32e6dc5bc9b6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -84,7 +84,6 @@
 
 #define SD_LISTEN_FDS_START 3
 
-
 static bool Handle_Write PARAMS(( CONN_ID Idx ));
 static bool Conn_Write PARAMS(( CONN_ID Idx, char *Data, size_t Len ));
 static int New_Connection PARAMS(( int Sock, bool IsSSL ));
@@ -100,7 +99,6 @@ static void Simple_Message PARAMS(( int Sock, const char *Msg ));
 static int NewListener PARAMS(( const char *listen_addr, UINT16 Port ));
 static void Account_Connection PARAMS((void));
 
-
 static array My_Listeners;
 static array My_ConnArray;
 static size_t NumConnections, NumConnectionsMax, NumConnectionsAccepted;
@@ -152,7 +150,9 @@ my_sd_listen_fds(void)
        if (!e || !*e)
                return -1;
        count = atoi(e);
+#ifdef HAVE_UNSETENV
        unsetenv("LISTEN_FDS");
+#endif
 
        return count;
 }
@@ -809,16 +809,6 @@ SSL_WantWrite(const CONNECTION *c)
        return false;
 }
 
-#else
-
-static inline bool
-SSL_WantRead(UNUSED const CONNECTION *c)
-{ return false; }
-
-static inline bool
-SSL_WantWrite(UNUSED const CONNECTION *c)
-{ return false; }
-
 #endif
 
 
@@ -881,8 +871,10 @@ Conn_Handler(void)
                        if (wdatalen > 0)
 #endif
                        {
+#ifdef SSL_SUPPORT
                                if (SSL_WantRead(&My_Connections[i]))
                                        continue;
+#endif
                                io_event_add(My_Connections[i].sock,
                                             IO_WANTWRITE);
                        }
@@ -982,6 +974,7 @@ va_dcl
        size_t len;
        bool ok;
        va_list ap;
+       int r;
 
        assert( Idx > NONE );
        assert( Format != NULL );
@@ -991,7 +984,8 @@ va_dcl
 #else
        va_start( ap );
 #endif
-       if (vsnprintf( buffer, COMMAND_LEN - 2, Format, ap ) >= COMMAND_LEN - 2 ) {
+       r = vsnprintf(buffer, COMMAND_LEN - 2, Format, ap);
+       if (r >= COMMAND_LEN - 2 || r == -1) {
                /*
                 * The string that should be written to the socket is longer
                 * than the allowed size of COMMAND_LEN bytes (including both
@@ -1012,6 +1006,13 @@ va_dcl
                 * an other server only routing the message!), so the only
                 * option left is to shorten the string and to hope that the
                 * result is still somewhat useful ...
+                *
+                * Note:
+                * C99 states that vsnprintf() "returns the number of characters
+                * that would have been printed if the n were unlimited"; but
+                * according to the Linux manual page "glibc until 2.0.6 would
+                * return -1 when the output was truncated" -- so we have to
+                * handle both cases ...
                 *                                                   -alex-
                 */
 
@@ -1913,7 +1914,7 @@ Handle_Buffer(CONN_ID Idx)
                ptr2 = strchr(array_start(&My_Connections[Idx].rbuf), '\n');
                if (ptr) {
                        /* Check if there is a single CR or LF _before_ the
-                        * corerct CR+LF line terminator:  */
+                        * correct CR+LF line terminator:  */
                        first_eol = ptr1 < ptr2 ? ptr1 : ptr2;
                        if (first_eol < ptr) {
                                /* Single CR or LF before CR+LF found */