X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fconn.c;h=75b77942d966858da2200fd6e7cb660b981b141b;hp=3f447c61ec367916f528f13a9da0852ac83eb0f4;hb=b130b35f48d19450240748425e12d21f2c38350f;hpb=5a424f60dad660815d89285da9a7a07e4991461a diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index 3f447c61..75b77942 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -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 @@ -14,15 +14,12 @@ #define CONN_MODULE #include "portab.h" -#include "conf-ssl.h" -#include "io.h" /** * @file * Connection management */ -#include "imp.h" #include #ifdef PROTOTYPES # include @@ -34,8 +31,9 @@ #include #include #include +#include #include -#include +#include #include #include #include @@ -51,30 +49,21 @@ # include /* for TCP Wrappers */ #endif -#include "array.h" -#include "defines.h" - -#include "exp.h" #include "conn.h" -#include "imp.h" #include "ngircd.h" -#include "array.h" -#include "client.h" #include "class.h" -#include "conf.h" -#include "conn-encoding.h" +#ifdef ICONV +# include "conn-encoding.h" +#endif #include "conn-ssl.h" #include "conn-zip.h" #include "conn-func.h" +#include "io.h" #include "log.h" #include "ng_ipaddr.h" #include "parse.h" #include "resolve.h" -#include "tool.h" - -#include "exp.h" - #define SERVER_WAIT (NONE - 1) @@ -84,7 +73,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 +88,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; @@ -811,16 +798,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 @@ -883,8 +860,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); } @@ -984,6 +963,7 @@ va_dcl size_t len; bool ok; va_list ap; + int r; assert( Idx > NONE ); assert( Format != NULL ); @@ -993,7 +973,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 @@ -1014,6 +995,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- */