X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Fclient.c;h=37b97d689e5ed900fac5bc86eb303a7190063e2a;hb=27b9d32bf2a851c4acbfdc4d9aa5a55d12c92c10;hp=32690288529499097c0b6d88c1127774202f51bd;hpb=3af0ece2bcf550cccd7b647c111ce503c2faa459;p=ngircd-alex.git diff --git a/src/ngircd/client.c b/src/ngircd/client.c index 32690288..37b97d68 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -62,6 +62,8 @@ static CLIENT *New_Client_Struct PARAMS(( void )); static void Generate_MyToken PARAMS(( CLIENT *Client )); static void Adjust_Counters PARAMS(( CLIENT *Client )); +static void Free_Client PARAMS(( CLIENT **Client )); + static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, int Type, const char *ID, const char *User, const char *Hostname, const char *Info, @@ -120,16 +122,15 @@ Client_Exit( void ) cnt = 0; c = My_Clients; - while( c ) - { + while(c) { cnt++; next = (CLIENT *)c->next; - if (c->account_name) - free(c->account_name); - free( c ); + Free_Client(&c); c = next; } - if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" ); + if (cnt) + Log(LOG_INFO, "Freed %d client structure%s.", + cnt, cnt == 1 ? "" : "s"); } /* Client_Exit */ @@ -220,7 +221,7 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, Generate_MyToken(client); if (Client_HasMode(client, 'a')) - strlcpy(client->away, DEFAULT_AWAY_MSG, sizeof(client->away)); + client->away = strndup(DEFAULT_AWAY_MSG, CLIENT_AWAY_LEN - 1); client->next = (POINTER *)My_Clients; My_Clients = client; @@ -320,11 +321,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen } } - if (c->account_name) - free(c->account_name); - if (c->cloaked) - free(c->cloaked); - free( c ); + Free_Client(&c); break; } last = c; @@ -366,6 +363,27 @@ Client_SetHostname( CLIENT *Client, const char *Hostname ) } /* Client_SetHostname */ +/** + * Set IP address to display for a client. + * + * @param Client The client. + * @param IPAText Textual representation of the IP address or NULL to unset. + */ +GLOBAL void +Client_SetIPAText(CLIENT *Client, const char *IPAText) +{ + assert(Client != NULL); + + if (Client->ipa_text) + free(Client->ipa_text); + + if (*IPAText) + Client->ipa_text = strndup(IPAText, CLIENT_HOST_LEN - 1); + else + Client->ipa_text = NULL; +} + + GLOBAL void Client_SetID( CLIENT *Client, const char *ID ) { @@ -467,7 +485,8 @@ Client_SetAccountName(CLIENT *Client, const char *AccountName) free(Client->account_name); if (*AccountName) - Client->account_name = strdup(AccountName); + Client->account_name = strndup(AccountName, + CLIENT_NICK_LEN - 1); else Client->account_name = NULL; } @@ -481,7 +500,11 @@ Client_SetAway( CLIENT *Client, const char *Txt ) assert( Client != NULL ); assert( Txt != NULL ); - strlcpy( Client->away, Txt, sizeof( Client->away )); + if (Client->away) + free(Client->away); + + Client->away = strndup(Txt, CLIENT_AWAY_LEN - 1); + LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client), Client_Mask(Client), Txt); } /* Client_SetAway */ @@ -786,6 +809,21 @@ Client_HostnameDisplayed(CLIENT *Client) return Client->cloaked; } +GLOBAL const char * +Client_IPAText(CLIENT *Client) +{ + assert(Client != NULL); + + /* Not a local client? */ + if (Client_Conn(Client) <= NONE) + return "0.0.0.0"; + + if (!Client->ipa_text) + return Conn_GetIPAInfo(Client_Conn(Client)); + else + return Client->ipa_text; +} + /** * Update (and generate, if necessary) the cloaked hostname of a client. * @@ -1367,6 +1405,11 @@ MyCount( CLIENT_TYPE Type ) } /* MyCount */ +/** + * Allocate and initialize new CLIENT strcuture. + * + * @return Pointer to CLIENT structure or NULL on error. + */ static CLIENT * New_Client_Struct( void ) { @@ -1389,8 +1432,29 @@ New_Client_Struct( void ) c->mytoken = -1; return c; -} /* New_Client */ +} +/** + * Free a CLIENT structure and its member variables. + */ +static void +Free_Client(CLIENT **Client) +{ + assert(Client != NULL); + assert(*Client != NULL); + + if ((*Client)->account_name) + free((*Client)->account_name); + if ((*Client)->away) + free((*Client)->away); + if ((*Client)->cloaked) + free((*Client)->cloaked); + if ((*Client)->ipa_text) + free((*Client)->ipa_text); + + free(*Client); + *Client = NULL; +} static void Generate_MyToken( CLIENT *Client )