Commit Diff


commit - 20ff63a8a1d92875130a5d6b059e011b1de2201d
commit + 46a191caf6bff88f8e4cf1a577ba33a60efb015e
blob - d307323e1031aa858962f9e9e2b4e513407eeaf8
blob + 07c504cc506825275979f490821b1eda50854b02
--- src/ngircd/conn.c
+++ src/ngircd/conn.c
@@ -17,7 +17,7 @@
 #include "portab.h"
 #include "io.h"
 
-static char UNUSED id[] = "$Id: conn.c,v 1.165 2005/07/22 21:31:05 alex Exp $";
+static char UNUSED id[] = "$Id: conn.c,v 1.166 2005/07/28 16:13:09 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -201,6 +201,7 @@ FreeRes_stat( CONNECTION *c )
 
 	io_close( c->res_stat->pipe[0] );
 
+	array_free(&c->res_stat->buffer);
 	free( c->res_stat );
 	c->res_stat = NULL;
 }
@@ -1121,7 +1122,6 @@ Handle_Buffer( CONN_ID Idx )
 #endif
 	char *ptr;
 	int len, delta;
-	unsigned int arraylen;
 	bool action, result;
 #ifdef ZLIB
 	bool old_z;
@@ -1137,16 +1137,12 @@ Handle_Buffer( CONN_ID Idx )
 			if( ! Unzip_Buffer( Idx )) return false;
 #endif
 
-		arraylen = array_bytes(&My_Connections[Idx].rbuf);
-		if (arraylen == 0)
+		if (0 == array_bytes(&My_Connections[Idx].rbuf))
 			break;
 
-		if (!array_cat0(&My_Connections[Idx].rbuf)) /* make sure buf is NULL terminated */
+		if (!array_cat0_temporary(&My_Connections[Idx].rbuf)) /* make sure buf is NULL terminated */
 			return false;
 
-		array_truncate(&My_Connections[Idx].rbuf, 1, arraylen); /* do not count trailing NULL */
-
-
 		/* A Complete Request end with CR+LF, see RFC 2812. */
 		ptr = strstr( array_start(&My_Connections[Idx].rbuf), "\r\n" );
 
@@ -1496,9 +1492,12 @@ void Read_Resolver_Result( int r_fd )
 	 * IDENT user name.*/
 
 	CLIENT *c;
-	int len, i, n;
+	int bytes_read, i, n;
+	unsigned int len;
 	RES_STAT *s;
 	char *ptr;
+	char *bufptr;
+	char readbuf[HOST_LEN];
 
 	Log( LOG_DEBUG, "Resolver: started, fd %d\n", r_fd );
 	/* Search associated connection ... */
@@ -1525,28 +1524,41 @@ void Read_Resolver_Result( int r_fd )
 	assert( s != NULL );
 
 	/* Read result from pipe */
-	len = read( r_fd, s->buffer + s->bufpos, sizeof( s->buffer ) - s->bufpos - 1 );
-	if( len < 0 )
+	bytes_read = read( r_fd, readbuf, sizeof readbuf -1 );
+	if( bytes_read < 0 )
 	{
 		/* Error! */
 		Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
 		FreeRes_stat( &My_Connections[i] );
 		return;
 	}
-	s->bufpos += len;
-	s->buffer[s->bufpos] = '\0';
+	len = (unsigned int) bytes_read;
+	readbuf[len] = '\0';
+	if (!array_catb(&s->buffer, readbuf, len)) { 
+		Log( LOG_CRIT, "Resolver: Can't append result %s to buffer: %s", readbuf, strerror( errno ));
+		FreeRes_stat(&My_Connections[i]);
+		return;
+	}
+
+	if (!array_cat0_temporary(&s->buffer)) {
+		Log( LOG_CRIT, "Resolver: Can't append result %s to buffer: %s", readbuf, strerror( errno ));
+		FreeRes_stat(&My_Connections[i]);
+		return;
+	}
 
 	/* If the result string is incomplete, return to main loop and
 	 * wait until we can read in more bytes. */
 #ifdef IDENTAUTH
 try_resolve:
 #endif
-	ptr = strchr( s->buffer, '\n' );
+	bufptr = (char*) array_start(&s->buffer);
+	assert(bufptr != NULL);
+	ptr = strchr( bufptr, '\n' );
 	if( ! ptr ) return;
 	*ptr = '\0';
 
 #ifdef DEBUG
-	Log( LOG_DEBUG, "Got result from resolver: \"%s\" (%d bytes), stage %d.", s->buffer, len, s->stage );
+	Log( LOG_DEBUG, "Got result from resolver: \"%s\" (%u bytes read), stage %d.", bufptr, len, s->stage);
 #endif
 
 	/* Okay, we got a complete result: this is a host name for outgoing
@@ -1563,15 +1575,14 @@ try_resolve:
 		{
 			switch(s->stage) {
 				case 0: /* host name */
-				strlcpy( My_Connections[i].host, s->buffer, sizeof( My_Connections[i].host ));
-				Client_SetHostname( c, s->buffer );
+				strlcpy( My_Connections[i].host, bufptr, sizeof( My_Connections[i].host));
+
+				Client_SetHostname( c, bufptr);
 #ifdef IDENTAUTH
 				/* clean up buffer for IDENT result */
-				len = strlen( s->buffer ) + 1;
-				assert((size_t) len <= sizeof( s->buffer ));
-				memmove( s->buffer, s->buffer + len, sizeof( s->buffer ) - len );
-				assert(len <= s->bufpos );
-				s->bufpos -= len;
+				len = strlen(bufptr) + 1;
+				assert(len <= array_bytes(&s->buffer));
+				array_moveleft(&s->buffer, 1, len);
 
 				/* Don't close pipe and clean up, but
 				 * instead wait for IDENT result */
@@ -1579,10 +1590,10 @@ try_resolve:
 				goto try_resolve;
 
 				case 1: /* IDENT user name */
-				if( s->buffer[0] )
-				{
-					Log( LOG_INFO, "IDENT lookup for connection %ld: \"%s\".", i, s->buffer );
-					Client_SetUser( c, s->buffer, true );
+				if (array_bytes(&s->buffer)) {
+					bufptr = (char*) array_start(&s->buffer);
+					Log( LOG_INFO, "IDENT lookup for connection %ld: \"%s\".", i, bufptr);
+					Client_SetUser( c, bufptr, true );
 				}
 				else Log( LOG_INFO, "IDENT lookup for connection %ld: no result.", i );
 #endif
@@ -1603,8 +1614,9 @@ try_resolve:
 		/* Search server ... */
 		n = Conf_GetServer( i );
 		assert( n > NONE );
-
-		strlcpy( Conf_Server[n].ip, s->buffer, sizeof( Conf_Server[n].ip ));
+		
+		bufptr = (char*) array_start(&s->buffer);
+		strlcpy( Conf_Server[n].ip, bufptr, sizeof( Conf_Server[n].ip ));
 	}
 
 	/* Clean up ... */
blob - 8e1749a30eaa574e76dfaed2c3e9679ea47fa701
blob + ef22614373dea19c749d6245551bd23bf06d0f81
--- src/ngircd/resolve.c
+++ src/ngircd/resolve.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: resolve.c,v 1.15 2005/07/25 09:20:10 fw Exp $";
+static char UNUSED id[] = "$Id: resolve.c,v 1.16 2005/07/28 16:13:09 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -350,7 +350,7 @@ New_Res_Stat( void )
 	}
 
 	s->stage = 0;
-	s->bufpos = 0;
+	array_init(&s->buffer);
 	s->pid = -1;
 
 	return s;
blob - 596a0832bebbc01dd4152c9bfbf4f39acbfb2182
blob + b13962a86b57bfda1c079c2e1e31243b62c75a97
--- src/ngircd/resolve.h
+++ src/ngircd/resolve.h
@@ -8,7 +8,7 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: resolve.h,v 1.8 2005/03/19 18:43:49 fw Exp $
+ * $Id: resolve.h,v 1.9 2005/07/28 16:13:09 fw Exp $
  *
  * Asynchronous resolver (header)
  */
@@ -17,6 +17,7 @@
 #ifndef __resolve_h__
 #define __resolve_h__
 
+#include "array.h"
 
 #ifdef HAVE_SYS_SELECT_H
 #	include <sys/select.h>
@@ -27,11 +28,10 @@
 
 typedef struct _Res_Stat
 {
-	int pid;			/* PID des Child-Prozess */
-	int pipe[2];			/* Pipe fuer IPC */
+	int pid;			/* PID of resolver process */
+	int pipe[2];			/* pipe for lookup result */
 	int stage;			/* Hostname/IP(0) or IDENT(1)? */
-	int bufpos;			/* Position in buffer */
-	char buffer[HOST_LEN];		/* Buffer */
+	array buffer;			/* resolved hostname / ident result */
 } RES_STAT;