mirror of
https://github.com/osmarks/ngircd.git
synced 2025-01-31 09:44:44 +00:00
changed RES_STAT buffer to array
This commit is contained in:
parent
20ff63a8a1
commit
46a191caf6
@ -17,7 +17,7 @@
|
|||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
#include "io.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 "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -201,6 +201,7 @@ FreeRes_stat( CONNECTION *c )
|
|||||||
|
|
||||||
io_close( c->res_stat->pipe[0] );
|
io_close( c->res_stat->pipe[0] );
|
||||||
|
|
||||||
|
array_free(&c->res_stat->buffer);
|
||||||
free( c->res_stat );
|
free( c->res_stat );
|
||||||
c->res_stat = NULL;
|
c->res_stat = NULL;
|
||||||
}
|
}
|
||||||
@ -1121,7 +1122,6 @@ Handle_Buffer( CONN_ID Idx )
|
|||||||
#endif
|
#endif
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int len, delta;
|
int len, delta;
|
||||||
unsigned int arraylen;
|
|
||||||
bool action, result;
|
bool action, result;
|
||||||
#ifdef ZLIB
|
#ifdef ZLIB
|
||||||
bool old_z;
|
bool old_z;
|
||||||
@ -1137,16 +1137,12 @@ Handle_Buffer( CONN_ID Idx )
|
|||||||
if( ! Unzip_Buffer( Idx )) return false;
|
if( ! Unzip_Buffer( Idx )) return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
arraylen = array_bytes(&My_Connections[Idx].rbuf);
|
if (0 == array_bytes(&My_Connections[Idx].rbuf))
|
||||||
if (arraylen == 0)
|
|
||||||
break;
|
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;
|
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. */
|
/* A Complete Request end with CR+LF, see RFC 2812. */
|
||||||
ptr = strstr( array_start(&My_Connections[Idx].rbuf), "\r\n" );
|
ptr = strstr( array_start(&My_Connections[Idx].rbuf), "\r\n" );
|
||||||
|
|
||||||
@ -1496,9 +1492,12 @@ void Read_Resolver_Result( int r_fd )
|
|||||||
* IDENT user name.*/
|
* IDENT user name.*/
|
||||||
|
|
||||||
CLIENT *c;
|
CLIENT *c;
|
||||||
int len, i, n;
|
int bytes_read, i, n;
|
||||||
|
unsigned int len;
|
||||||
RES_STAT *s;
|
RES_STAT *s;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
char *bufptr;
|
||||||
|
char readbuf[HOST_LEN];
|
||||||
|
|
||||||
Log( LOG_DEBUG, "Resolver: started, fd %d\n", r_fd );
|
Log( LOG_DEBUG, "Resolver: started, fd %d\n", r_fd );
|
||||||
/* Search associated connection ... */
|
/* Search associated connection ... */
|
||||||
@ -1525,28 +1524,41 @@ void Read_Resolver_Result( int r_fd )
|
|||||||
assert( s != NULL );
|
assert( s != NULL );
|
||||||
|
|
||||||
/* Read result from pipe */
|
/* Read result from pipe */
|
||||||
len = read( r_fd, s->buffer + s->bufpos, sizeof( s->buffer ) - s->bufpos - 1 );
|
bytes_read = read( r_fd, readbuf, sizeof readbuf -1 );
|
||||||
if( len < 0 )
|
if( bytes_read < 0 )
|
||||||
{
|
{
|
||||||
/* Error! */
|
/* Error! */
|
||||||
Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
|
Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
|
||||||
FreeRes_stat( &My_Connections[i] );
|
FreeRes_stat( &My_Connections[i] );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s->bufpos += len;
|
len = (unsigned int) bytes_read;
|
||||||
s->buffer[s->bufpos] = '\0';
|
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
|
/* If the result string is incomplete, return to main loop and
|
||||||
* wait until we can read in more bytes. */
|
* wait until we can read in more bytes. */
|
||||||
#ifdef IDENTAUTH
|
#ifdef IDENTAUTH
|
||||||
try_resolve:
|
try_resolve:
|
||||||
#endif
|
#endif
|
||||||
ptr = strchr( s->buffer, '\n' );
|
bufptr = (char*) array_start(&s->buffer);
|
||||||
|
assert(bufptr != NULL);
|
||||||
|
ptr = strchr( bufptr, '\n' );
|
||||||
if( ! ptr ) return;
|
if( ! ptr ) return;
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
/* Okay, we got a complete result: this is a host name for outgoing
|
/* Okay, we got a complete result: this is a host name for outgoing
|
||||||
@ -1563,15 +1575,14 @@ try_resolve:
|
|||||||
{
|
{
|
||||||
switch(s->stage) {
|
switch(s->stage) {
|
||||||
case 0: /* host name */
|
case 0: /* host name */
|
||||||
strlcpy( My_Connections[i].host, s->buffer, sizeof( My_Connections[i].host ));
|
strlcpy( My_Connections[i].host, bufptr, sizeof( My_Connections[i].host));
|
||||||
Client_SetHostname( c, s->buffer );
|
|
||||||
|
Client_SetHostname( c, bufptr);
|
||||||
#ifdef IDENTAUTH
|
#ifdef IDENTAUTH
|
||||||
/* clean up buffer for IDENT result */
|
/* clean up buffer for IDENT result */
|
||||||
len = strlen( s->buffer ) + 1;
|
len = strlen(bufptr) + 1;
|
||||||
assert((size_t) len <= sizeof( s->buffer ));
|
assert(len <= array_bytes(&s->buffer));
|
||||||
memmove( s->buffer, s->buffer + len, sizeof( s->buffer ) - len );
|
array_moveleft(&s->buffer, 1, len);
|
||||||
assert(len <= s->bufpos );
|
|
||||||
s->bufpos -= len;
|
|
||||||
|
|
||||||
/* Don't close pipe and clean up, but
|
/* Don't close pipe and clean up, but
|
||||||
* instead wait for IDENT result */
|
* instead wait for IDENT result */
|
||||||
@ -1579,10 +1590,10 @@ try_resolve:
|
|||||||
goto try_resolve;
|
goto try_resolve;
|
||||||
|
|
||||||
case 1: /* IDENT user name */
|
case 1: /* IDENT user name */
|
||||||
if( s->buffer[0] )
|
if (array_bytes(&s->buffer)) {
|
||||||
{
|
bufptr = (char*) array_start(&s->buffer);
|
||||||
Log( LOG_INFO, "IDENT lookup for connection %ld: \"%s\".", i, s->buffer );
|
Log( LOG_INFO, "IDENT lookup for connection %ld: \"%s\".", i, bufptr);
|
||||||
Client_SetUser( c, s->buffer, true );
|
Client_SetUser( c, bufptr, true );
|
||||||
}
|
}
|
||||||
else Log( LOG_INFO, "IDENT lookup for connection %ld: no result.", i );
|
else Log( LOG_INFO, "IDENT lookup for connection %ld: no result.", i );
|
||||||
#endif
|
#endif
|
||||||
@ -1603,8 +1614,9 @@ try_resolve:
|
|||||||
/* Search server ... */
|
/* Search server ... */
|
||||||
n = Conf_GetServer( i );
|
n = Conf_GetServer( i );
|
||||||
assert( n > NONE );
|
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 ... */
|
/* Clean up ... */
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "portab.h"
|
#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 "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -350,7 +350,7 @@ New_Res_Stat( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
s->stage = 0;
|
s->stage = 0;
|
||||||
s->bufpos = 0;
|
array_init(&s->buffer);
|
||||||
s->pid = -1;
|
s->pid = -1;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* Please read the file COPYING, README and AUTHORS for more information.
|
* 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)
|
* Asynchronous resolver (header)
|
||||||
*/
|
*/
|
||||||
@ -17,6 +17,7 @@
|
|||||||
#ifndef __resolve_h__
|
#ifndef __resolve_h__
|
||||||
#define __resolve_h__
|
#define __resolve_h__
|
||||||
|
|
||||||
|
#include "array.h"
|
||||||
|
|
||||||
#ifdef HAVE_SYS_SELECT_H
|
#ifdef HAVE_SYS_SELECT_H
|
||||||
# include <sys/select.h>
|
# include <sys/select.h>
|
||||||
@ -27,11 +28,10 @@
|
|||||||
|
|
||||||
typedef struct _Res_Stat
|
typedef struct _Res_Stat
|
||||||
{
|
{
|
||||||
int pid; /* PID des Child-Prozess */
|
int pid; /* PID of resolver process */
|
||||||
int pipe[2]; /* Pipe fuer IPC */
|
int pipe[2]; /* pipe for lookup result */
|
||||||
int stage; /* Hostname/IP(0) or IDENT(1)? */
|
int stage; /* Hostname/IP(0) or IDENT(1)? */
|
||||||
int bufpos; /* Position in buffer */
|
array buffer; /* resolved hostname / ident result */
|
||||||
char buffer[HOST_LEN]; /* Buffer */
|
|
||||||
} RES_STAT;
|
} RES_STAT;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user