Client_GetFromConn() removed and replaced with new function Conn_GetClient()

This commit is contained in:
Florian Westphal 2006-04-23 10:37:27 +00:00
parent 8067bab106
commit 87f4b1c6f6
9 changed files with 45 additions and 49 deletions

View File

@ -17,7 +17,7 @@
#include "portab.h"
static char UNUSED id[] = "$Id: client.c,v 1.90 2006/03/24 23:25:38 fw Exp $";
static char UNUSED id[] = "$Id: client.c,v 1.91 2006/04/23 10:37:27 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -563,27 +563,6 @@ Client_ModeDel( CLIENT *Client, char Mode )
} /* Client_ModeDel */
GLOBAL CLIENT *
Client_GetFromConn( CONN_ID Idx )
{
/* return Client-Structure that belongs to the local Connection Idx.
* If none is found, return NULL.
*/
CLIENT *c;
assert( Idx >= 0 );
c = My_Clients;
while( c )
{
if( c->conn_id == Idx ) return c;
c = (CLIENT *)c->next;
}
return NULL;
} /* Client_GetFromConn */
GLOBAL CLIENT *
Client_Search( char *Nick )
{

View File

@ -8,7 +8,7 @@
* (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information.
*
* $Id: client.h,v 1.41 2006/03/11 01:37:31 alex Exp $
* $Id: client.h,v 1.42 2006/04/23 10:37:27 fw Exp $
*
* Client management (header)
*/
@ -30,6 +30,7 @@
#define CLIENT_TYPE int
#include "defines.h"
#if defined(__client_c__) | defined(S_SPLINT_S)
@ -86,7 +87,6 @@ GLOBAL void Client_DestroyNow PARAMS(( CLIENT *Client ));
GLOBAL CLIENT *Client_ThisServer PARAMS(( void ));
GLOBAL CLIENT *Client_GetFromConn PARAMS(( CONN_ID Idx ));
GLOBAL CLIENT *Client_GetFromToken PARAMS(( CLIENT *Client, int Token ));
GLOBAL CLIENT *Client_Search PARAMS(( char *ID ));

View File

@ -16,7 +16,7 @@
#include "portab.h"
static char UNUSED id[] = "$Id: conn-func.c,v 1.8 2005/09/04 23:38:32 alex Exp $";
static char UNUSED id[] = "$Id: conn-func.c,v 1.9 2006/04/23 10:37:27 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -177,7 +177,7 @@ Conn_StartTime( CONN_ID Idx )
assert(Idx > NONE);
/* Search client structure for this link ... */
c = Client_GetFromConn(Idx);
c = Conn_GetClient(Idx);
if(c != NULL)
return Client_StartTime(c);

View File

@ -17,7 +17,7 @@
#include "portab.h"
#include "io.h"
static char UNUSED id[] = "$Id: conn.c,v 1.191 2006/03/18 22:27:09 fw Exp $";
static char UNUSED id[] = "$Id: conn.c,v 1.192 2006/04/23 10:37:27 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -152,7 +152,7 @@ cb_connserver(int sock, UNUSED short what)
/* Clean up the CLIENT structure (to avoid silly log
* messages) and call Conn_Close() to do the rest. */
c = Client_GetFromConn(idx);
c = Conn_GetClient(idx);
if (c)
Client_DestroyNow(c);
@ -602,7 +602,6 @@ va_dcl
#endif
len = strlcat( buffer, "\r\n", sizeof( buffer ));
assert(len < COMMAND_LEN);
ok = Conn_Write(Idx, buffer, len);
My_Connections[Idx].msg_out++;
@ -704,7 +703,7 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
Log( LOG_INFO, "Shutting down connection %d (%s) with %s:%d ...", Idx, LogMsg ? LogMsg : FwdMsg, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ));
/* Search client, if any */
c = Client_GetFromConn( Idx );
c = Conn_GetClient( Idx );
/* Should the client be informed? */
if (InformClient) {
@ -734,7 +733,7 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
(void)Handle_Write( Idx );
/* Search client, if any (re-check!) */
c = Client_GetFromConn( Idx );
c = Conn_GetClient( Idx );
/* Shut down socket */
if( ! io_close( My_Connections[Idx].sock ))
@ -809,7 +808,7 @@ Conn_SyncServerStruct( void )
continue;
/* Server connection? */
client = Client_GetFromConn( i );
client = Conn_GetClient( i );
if(( ! client ) || ( Client_Type( client ) != CLIENT_SERVER )) continue;
for( c = 0; c < MAX_SERVERS; c++ )
@ -973,6 +972,7 @@ New_Connection( int Sock )
Init_Conn_Struct( new_sock );
My_Connections[new_sock].sock = new_sock;
My_Connections[new_sock].addr = new_addr;
My_Connections[new_sock].client = c;
/* register callback */
if (!io_event_create( new_sock, IO_WANTREAD, cb_clientserver)) {
@ -1083,7 +1083,7 @@ Read_Request( CONN_ID Idx )
* registered as a user, server or service connection. Don't update
* otherwise, so users have at least Conf_PongTimeout seconds time to
* register with the IRC server -- see Check_Connections(). */
c = Client_GetFromConn(Idx);
c = Conn_GetClient(Idx);
if (c && (Client_Type(c) == CLIENT_USER
|| Client_Type(c) == CLIENT_SERVER
|| Client_Type(c) == CLIENT_SERVICE))
@ -1216,7 +1216,7 @@ Check_Connections( void )
if (My_Connections[i].sock < 0)
continue;
c = Client_GetFromConn( i );
c = Conn_GetClient( i );
if( c && (( Client_Type( c ) == CLIENT_USER ) || ( Client_Type( c ) == CLIENT_SERVER ) || ( Client_Type( c ) == CLIENT_SERVICE )))
{
/* connected User, Server or Service */
@ -1366,6 +1366,7 @@ New_Server( int Server )
Conf_Server[Server].conn_id = new_sock;
My_Connections[new_sock].sock = new_sock;
My_Connections[new_sock].addr = new_addr;
My_Connections[new_sock].client = c;
strlcpy( My_Connections[new_sock].host, Conf_Server[Server].host,
sizeof(My_Connections[new_sock].host ));
@ -1523,7 +1524,7 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
* incoming connections.*/
assert ( My_Connections[i].sock >= 0 );
/* Incoming connection. Search client ... */
c = Client_GetFromConn( i );
c = Conn_GetClient( i );
assert( c != NULL );
/* Only update client information of unregistered clients */
@ -1551,8 +1552,8 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
static void
Simple_Message( int Sock, const char *Msg )
{
size_t len;
char buf[COMMAND_LEN];
size_t len;
/* Write "simple" message to socket, without using compression
* or even the connection write buffers. Used e.g. for error
* messages by New_Connection(). */
@ -1561,7 +1562,6 @@ Simple_Message( int Sock, const char *Msg )
strlcpy( buf, Msg, sizeof buf - 2);
len = strlcat( buf, "\r\n", sizeof buf);
assert(len < COMMAND_LEN);
(void)write(Sock, buf, len);
} /* Simple_Error */
@ -1579,5 +1579,20 @@ Count_Connections( struct sockaddr_in addr_in )
} /* Count_Connections */
GLOBAL CLIENT *
Conn_GetClient( CONN_ID Idx )
{
/* return Client-Structure that belongs to the local Connection Idx.
* If none is found, return NULL.
*/
CONNECTION *c;
assert( Idx >= 0 );
c = array_get(&My_ConnArray, sizeof (CONNECTION), Idx);
assert(c != NULL);
return c ? c->client : NULL;
}
/* -eof- */

View File

@ -8,7 +8,7 @@
* (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information.
*
* $Id: conn.h,v 1.40 2006/02/02 21:00:22 fw Exp $
* $Id: conn.h,v 1.41 2006/04/23 10:37:27 fw Exp $
*
* Connection management (header)
*/
@ -31,6 +31,7 @@
typedef int CONN_ID;
#include "client.h"
#ifdef CONN_MODULE
@ -66,6 +67,7 @@ typedef struct _Connection
long msg_in, msg_out; /* Received and sent IRC messages */
int flag; /* Flag (see "irc-write" module) */
UINT16 options; /* Link options / connection state */
CLIENT *client; /* pointer to client structure */
#ifdef ZLIB
ZIPDATA zip; /* Compression information */
#endif /* ZLIB */
@ -93,7 +95,7 @@ GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool In
GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
#endif
/* -eof- */

View File

@ -14,7 +14,7 @@
#include "portab.h"
static char UNUSED id[] = "$Id: irc-info.c,v 1.31 2006/01/27 17:19:58 fw Exp $";
static char UNUSED id[] = "$Id: irc-info.c,v 1.32 2006/04/23 10:37:27 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -377,7 +377,7 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
con = Conn_First( );
while( con != NONE )
{
cl = Client_GetFromConn( con );
cl = Conn_GetClient( con );
if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
{
/* Server link or our own connection */

View File

@ -14,7 +14,7 @@
#include "portab.h"
static char UNUSED id[] = "$Id: irc-oper.c,v 1.24 2005/07/31 20:13:08 alex Exp $";
static char UNUSED id[] = "$Id: irc-oper.c,v 1.25 2006/04/23 10:37:27 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -208,7 +208,7 @@ IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
if( ! Conf_DisableServer( Req->argv[0] )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
/* Are we still connected or were we killed, too? */
if( Client_GetFromConn( my_conn )) return CONNECTED;
if( Conn_GetClient( my_conn )) return CONNECTED;
else return DISCONNECTED;
} /* IRC_CONNECT */

View File

@ -14,7 +14,7 @@
#include "portab.h"
static char UNUSED id[] = "$Id: irc.c,v 1.128 2005/08/02 23:19:22 alex Exp $";
static char UNUSED id[] = "$Id: irc.c,v 1.129 2006/04/23 10:37:27 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -160,7 +160,7 @@ IRC_KILL( CLIENT *Client, REQUEST *Req )
Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
/* Are we still connected or were we killed, too? */
if(( my_conn > NONE ) && ( Client_GetFromConn( my_conn )))
if(( my_conn > NONE ) && ( Conn_GetClient( my_conn )))
return CONNECTED;
else
return DISCONNECTED;

View File

@ -12,7 +12,7 @@
#include "portab.h"
static char UNUSED id[] = "$Id: parse.c,v 1.66 2005/09/04 23:42:24 alex Exp $";
static char UNUSED id[] = "$Id: parse.c,v 1.67 2006/04/23 10:37:27 fw Exp $";
/**
* @file
@ -277,7 +277,7 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
if( ! Req->prefix ) return true;
/* Client-Struktur der Connection ermitteln */
client = Client_GetFromConn( Idx );
client = Conn_GetClient( Idx );
assert( client != NULL );
/* nur validieren, wenn bereits registrierte Verbindung */
@ -306,7 +306,7 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
{
/* das angegebene Prefix ist aus dieser Richtung, also
* aus der gegebenen Connection, ungueltig! */
Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Client_GetFromConn( Idx )), Idx, Req->command );
Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Conn_GetClient( Idx )), Idx, Req->command );
Conn_Close( Idx, NULL, "Spoofed prefix", true);
*Closed = true;
return false;
@ -354,7 +354,7 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
assert( Req != NULL );
assert( Req->command != NULL );
client = Client_GetFromConn( Idx );
client = Conn_GetClient( Idx );
assert( client != NULL );
/* Statuscode? */