/* * ---------------------------------------------------------------- * Night Light IRC Proxy - Client Functions * ---------------------------------------------------------------- * Copyright (C) 1997-2007 Jonas Kvinge * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Last modified by: * Jonas Kvinge (24.11.2007) * */ #define CLIENT_C #define NEED_SYS_TYPES_H 1 /* Extra types */ #define NEED_SYS_PARAM_H 1 /* Some systems need this */ #define NEED_LIMITS_H 0 /* Kernel limits */ #define NEED_STDARG_H 1 /* va_list, etc */ #define NEED_ERRNO_H 1 /* errno */ #define NEED_CTYPE_H 0 /* isdigit(), etc */ #define NEED_NETINET_IN_H 1 /* in_addr, sockaddr_in, etc */ #define NEED_ARPA_INET_H 1 /* inet_ntoa(), inet_aton(), etc */ #define NEED_STDIO_H 1 /* Standard C UNIX functions */ #define NEED_STDLIB_H 1 /* malloc(), exit(), atoi(), etc */ #define NEED_TIME_H 1 /* time(), etc */ #define NEED_SYSCTL_H 0 /* sysctl(), etc */ #define NEED_SYS_STAT_H 0 /* chmod(), mkdir(), etc */ #define NEED_SYS_UIO_H 0 /* iovec, etc */ #define NEED_FCNTL_H 1 /* open(), creat(), fcntl(), etc */ #define NEED_SYS_IOCTL_H 0 /* ioctl(), etc */ #define NEED_SYS_FILIO_H 0 /* Solaris need this for ioctl(), etc */ #define NEED_UNISTD_H 1 /* Unix standard functions */ #define NEED_STRING_H 1 /* C string functions */ #define NEED_SIGNAL_H 0 /* Signal functions */ #define NEED_SYS_SOCKET_H 1 /* Socket functions */ #define NEED_NETDB_H 1 /* Network database functions */ #define NEED_ARPA_NAMESER_H 0 /* Nameserver definitions */ #define NEED_GETUSERPW_HEADERS 0 /* Functions to retrive system passwords */ #define NEED_ARES 0 /* Functions needed for ares */ #define NEED_SSL 1 /* Needed for SSL support */ #include "includes.h" #include "listen.h" #include "client.h" #include "client_connection.h" /* VARIABLES - JONAS (31.07.2001) */ struct Client_Struct *Client_Head = NULL; struct Client_Struct *Client_Tail = NULL; unsigned long int G_Clients = 0; /* CLIENT_ADD - JONAS (01.08.2001) */ struct Client_Struct *client_add(struct Listen_Struct *ListenS, const char *const HostIPSPT) { struct Client_Struct *ClientS = NULL; struct Client_Struct *ClientS_NEW = NULL; assert(HostIPSPT != NULL); ClientS_NEW = malloc(sizeof(struct Client_Struct)); if (ClientS_NEW == NULL) { aerrno = AEMALLOC; return(NULL); } memset(ClientS_NEW, 0, sizeof(struct Client_Struct)); ClientS_NEW->HostIPS = strdup(HostIPSPT); if (ClientS_NEW->HostIPS == NULL) { free(ClientS_NEW); aerrno = AEMALLOC; return(NULL); } ClientS_NEW->PortH = 0; ClientS_NEW->PortN = 0; ClientS_NEW->FD = FD_NONE; ClientS_NEW->Time = NOW; ClientS_NEW->ListenS = ListenS; memset(&ClientS_NEW->INAddr, 0, sizeof(ClientS_NEW->INAddr)); #if IPV6_SUPPORT memset(&ClientS_NEW->INAddr6, 0, sizeof(ClientS_NEW->INAddr6)); #endif Client_SetSocket(ClientS_NEW); if (Client_Head == NULL) { Client_Head = ClientS_NEW; Client_Tail = ClientS_NEW; } else { ClientS = Client_Tail; ClientS->Next = ClientS_NEW; ClientS_NEW->Prev = ClientS; Client_Tail = ClientS_NEW; } G_Clients++; aerrno = AESUCCESS; return(ClientS_NEW); } /* CLIENT_REM FUNCTION - JONAS (01.08.2001) */ void client_rem(struct Client_Struct *ClientS) { assert(ClientS != NULL); if (ClientS->Prev == NULL) { Client_Head = ClientS->Next; } else { ClientS->Prev->Next = ClientS->Next; } if (ClientS->Next == NULL) { Client_Tail = ClientS->Prev; } else { ClientS->Next->Prev = ClientS->Prev; } free(ClientS->HostName); free(ClientS->HostIPS); free(ClientS->Nick); free(ClientS->User); free(ClientS->Host); free(ClientS->Pass); free(ClientS->RecvBuffer); free(ClientS->SendBuffer); free(ClientS); G_Clients--; }