* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
*
- * $Id: conn.c,v 1.86 2002/11/02 23:00:45 alex Exp $
+ * $Id: conn.c,v 1.90 2002/11/19 12:50:20 alex Exp $
*
* connect.h: Verwaltung aller Netz-Verbindungen ("connections")
*/
time_t lastprivmsg; /* Letzte PRIVMSG */
time_t delaytime; /* Nicht beachten bis ("penalty") */
LONG bytes_in, bytes_out; /* Counter fuer Statistik */
- BOOLEAN flagged; /* Channel ist "markiert" (vgl. "irc-write"-Modul) */
+ INT flag; /* Channel-Flag (vgl. "irc-write"-Modul) */
} CONNECTION;
BOOLEAN ok;
va_list ap;
- assert( Idx >= 0 );
+ assert( Idx > NONE );
assert( Format != NULL );
#ifdef PROTOTYPES
/* Daten in Socket schreiben. Bei "fatalen" Fehlern wird
* der Client disconnectiert und FALSE geliefert. */
- assert( Idx >= 0 );
+ assert( Idx > NONE );
assert( Data != NULL );
assert( Len > 0 );
CLIENT *c;
- assert( Idx >= 0 );
+ assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
c = Client_GetFromConn( Idx );
}
/* Startzeit des naechsten Connect-Versuchs modifizieren? */
- if(( My_Connections[Idx].our_server >= 0 ) && ( Conf_Server[My_Connections[Idx].our_server].lasttry < time( NULL ) - Conf_ConnectRetry ))
+ if(( My_Connections[Idx].our_server > NONE ) && ( Conf_Server[My_Connections[Idx].our_server].lasttry < time( NULL ) - Conf_ConnectRetry ))
{
/* Okay, die Verbindung stand schon "genuegend lange":
* lasttry-Zeitpunkt so setzen, dass der naechste
{
/* Idle-Timer zuruecksetzen */
- assert( Idx >= 0 );
+ assert( Idx > NONE );
My_Connections[Idx].lastprivmsg = time( NULL );
}
{
/* Idle-Time einer Verbindung liefern (in Sekunden) */
- assert( Idx >= 0 );
+ assert( Idx > NONE );
return time( NULL ) - My_Connections[Idx].lastprivmsg;
} /* Conn_GetIdle */
{
/* Zeitpunkt des letzten PING liefern */
- assert( Idx >= 0 );
+ assert( Idx > NONE );
return My_Connections[Idx].lastping;
} /* Conn_LastPing */
time_t t;
- assert( Idx >= 0 );
+ assert( Idx > NONE );
assert( Seconds >= 0 );
t = time( NULL ) + Seconds;
GLOBAL VOID
Conn_ResetPenalty( CONN_ID Idx )
{
- assert( Idx >= NONE );
+ assert( Idx > NONE );
My_Connections[Idx].delaytime = 0;
} /* Conn_ResetPenalty */
LONG i;
- for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flagged = FALSE;
+ for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
} /* Conn_ClearFlags */
-GLOBAL BOOLEAN
+GLOBAL INT
Conn_Flag( CONN_ID Idx )
{
/* Ist eine Connection markiert (TRUE) oder nicht? */
- assert( Idx >= NONE );
- return My_Connections[Idx].flagged;
+ assert( Idx > NONE );
+ return My_Connections[Idx].flag;
} /* Conn_Flag */
GLOBAL VOID
-Conn_SetFlag( CONN_ID Idx )
+Conn_SetFlag( CONN_ID Idx, INT Flag )
{
/* Connection markieren */
- assert( Idx >= NONE );
- My_Connections[Idx].flagged = TRUE;
+ assert( Idx > NONE );
+ My_Connections[Idx].flag = Flag;
} /* Conn_SetFlag */
LONG i = NONE;
- assert( Idx >= NONE );
+ assert( Idx > NONE );
for( i = Idx + 1; i < Pool_Size; i++ )
{
} /* Conn_Next */
+GLOBAL VOID
+Conn_SetServer( CONN_ID Idx, INT ConfServer )
+{
+ /* Connection als Server markieren: Index des konfigurierten
+ * Servers speichern. Verbindung muss bereits bestehen! */
+
+ assert( Idx > NONE );
+ assert( My_Connections[Idx].sock > NONE );
+
+ My_Connections[Idx].our_server = ConfServer;
+} /* Conn_SetServer */
+
+
LOCAL BOOLEAN
Try_Write( CONN_ID Idx )
{
fd_set write_socket;
- assert( Idx >= 0 );
+ assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
assert( My_Connections[Idx].wdatalen > 0 );
CONN_ID idx;
- assert( Sock >= 0 );
+ assert( Sock > NONE );
if( FD_ISSET( Sock, &My_Listeners ))
{
Log( LOG_DEBUG, "Connection %d with \"%s:%d\" established, now sendig PASS and SERVER ...", Idx, My_Connections[Idx].host, Conf_Server[My_Connections[Idx].our_server].port );
/* PASS und SERVER verschicken */
- Conn_WriteStr( Idx, "PASS %s %s", Conf_Server[My_Connections[Idx].our_server].pwd, NGIRCd_ProtoID );
+ Conn_WriteStr( Idx, "PASS %s %s", Conf_Server[My_Connections[Idx].our_server].pwd_out, NGIRCd_ProtoID );
return Conn_WriteStr( Idx, "SERVER %s :%s", Conf_ServerName, Conf_ServerInfo );
}
POINTER *ptr;
LONG new_size;
- assert( Sock >= 0 );
+ assert( Sock > NONE );
new_sock_len = sizeof( new_addr );
new_sock = accept( Sock, (struct sockaddr *)&new_addr, (socklen_t *)&new_sock_len );
CONN_ID idx;
- assert( Sock >= 0 );
+ assert( Sock > NONE );
for( idx = 0; idx < Pool_Size; idx++ ) if( My_Connections[idx].sock == Sock ) break;
INT len;
- assert( Idx >= 0 );
+ assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
if( READBUFFER_LEN - My_Connections[Idx].rdatalen - 2 < 0 )
struct sockaddr_in new_addr;
struct in_addr inaddr;
- INT new_sock;
+ INT res, new_sock;
CLIENT *c;
- assert( Server >= 0 );
- assert( Idx >= 0 );
+ assert( Server > NONE );
+ assert( Idx > NONE );
/* Wurde eine gueltige IP-Adresse gefunden? */
if( ! Conf_Server[Server].ip[0] )
if( ! Init_Socket( new_sock )) return;
- connect( new_sock, (struct sockaddr *)&new_addr, sizeof( new_addr ));
- if( errno != EINPROGRESS )
+ res = connect( new_sock, (struct sockaddr *)&new_addr, sizeof( new_addr ));
+ if(( res != 0 ) && ( errno != EINPROGRESS ))
{
-
+ Log( LOG_CRIT, "Can't connect socket: %s!", strerror( errno ));
close( new_sock );
Init_Conn_Struct( Idx );
- Log( LOG_CRIT, "Can't connect socket: %s!", strerror( errno ));
return;
}
My_Connections[Idx].delaytime = 0;
My_Connections[Idx].bytes_in = 0;
My_Connections[Idx].bytes_out = 0;
- My_Connections[Idx].flagged = FALSE;
+ My_Connections[Idx].flag = 0;
} /* Init_Conn_Struct */
else
{
/* Ausgehende Verbindung (=Server): IP setzen */
- assert( My_Connections[i].our_server >= 0 );
+ assert( My_Connections[i].our_server > NONE );
strcpy( Conf_Server[My_Connections[i].our_server].ip, result );
}