1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-05-21 08:34:10 +00:00

Code cleanup of IRC_SQUIT() in preparation to deal with bug #73.

This commit is contained in:
Alexander Barton 2008-04-09 19:49:34 +02:00
parent 926204cacd
commit bce16c2864

View File

@ -266,6 +266,10 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
} /* IRC_NJOIN */ } /* IRC_NJOIN */
/**
* Handler for the IRC command "SQUIT".
* See RFC 2813 section 4.1.2 and RFC 2812 section 3.1.8.
*/
GLOBAL bool GLOBAL bool
IRC_SQUIT(CLIENT * Client, REQUEST * Req) IRC_SQUIT(CLIENT * Client, REQUEST * Req)
{ {
@ -275,34 +279,41 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
assert(Client != NULL); assert(Client != NULL);
assert(Req != NULL); assert(Req != NULL);
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* Bad number of arguments? */
if (Req->argc != 2)
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
Client_ID(Client), Req->command);
Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] ); Log(LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...",
Client_ID(Client), Req->argv[0], Req->argv[1]);
target = Client_Search(Req->argv[0]); target = Client_Search(Req->argv[0]);
if( ! target ) if (!target) {
{ /* The server is (already) unknown */
Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] ); Log(LOG_WARNING,
"Got SQUIT from %s for unknown server \"%s\"!?",
Client_ID(Client), Req->argv[0]);
return CONNECTED; return CONNECTED;
} }
if( Req->argv[1][0] ) if (Req->argv[1][0]) {
{ if (strlen(Req->argv[1]) > LINE_LEN)
if( strlen( Req->argv[1] ) > LINE_LEN ) Req->argv[1][LINE_LEN] = '\0'; Req->argv[1][LINE_LEN] = '\0';
snprintf( msg, sizeof( msg ), "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client )); snprintf(msg, sizeof(msg), "%s (SQUIT from %s).", Req->argv[1],
} Client_ID(Client));
else snprintf( msg, sizeof( msg ), "Got SQUIT from %s.", Client_ID( Client )); } else
snprintf(msg, sizeof(msg), "Got SQUIT from %s.",
Client_ID(Client));
if( Client_Conn( target ) > NONE ) if (Client_Conn(target) > NONE) {
{ /* We are directly connected to this server */
/* This server has the connection */ if (Req->argv[1][0])
if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], true); Conn_Close(Client_Conn(target), msg, Req->argv[1],
else Conn_Close( Client_Conn( target ), msg, NULL, true); true);
return DISCONNECTED;
}
else else
{ Conn_Close(Client_Conn(target), msg, NULL, true);
/* connection was on another server */ return DISCONNECTED;
} else {
Client_Destroy(target, msg, Req->argv[1], false); Client_Destroy(target, msg, Req->argv[1], false);
return CONNECTED; return CONNECTED;
} }