X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fsocket.h;h=a42696379a5eaf45c145a0528fcf059d07f58f72;hb=d1ddbd62f91d4b9453447b5d25f5e41e807b0010;hp=f7590c72d5b746caaa7eb8414ce5d13938f5d0d1;hpb=77d5c9f765702a06a1ad77f239d1cbe2d9b11662;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/socket.h b/include/socket.h index f7590c72d..a42696379 100644 --- a/include/socket.h +++ b/include/socket.h @@ -96,10 +96,10 @@ namespace irc * or a negative value upon failure (negative values are invalid file * descriptors) */ - CoreExport int OpenTCPSocket(const char* addr, int socktype = SOCK_STREAM); + CoreExport int OpenTCPSocket(const std::string& addr, int socktype = SOCK_STREAM); /** Return the size of the structure for syscall passing */ - CoreExport int sa_size(irc::sockets::sockaddrs& sa); + CoreExport int sa_size(const irc::sockets::sockaddrs& sa); /** Convert an address-port pair into a binary sockaddr * @param addr The IP address, IPv4 or IPv6 @@ -107,19 +107,23 @@ namespace irc * @param sa The structure to place the result in. Will be zeroed prior to conversion * @return true if the conversion was successful, false if not. */ - CoreExport int aptosa(const char* addr, int port, irc::sockets::sockaddrs* sa); + CoreExport bool aptosa(const std::string& addr, int port, irc::sockets::sockaddrs* sa); /** Convert a binary sockaddr to an address-port pair * @param sa The structure to convert * @param addr the IP address * @param port the port * @return true if the conversion was successful, false if unknown address family */ - CoreExport int satoap(const irc::sockets::sockaddrs* sa, std::string& addr, int &port); + CoreExport bool satoap(const irc::sockets::sockaddrs* sa, std::string& addr, int &port); + /** Convert a binary sockaddr to a user-readable string. + * This means IPv6 addresses are written as [::1]:6667, and *:6668 is used for 0.0.0.0:6668 + * @param sa The structure to convert + * @return The string; "" if not a valid address + */ + CoreExport std::string satouser(const irc::sockets::sockaddrs* sa); } } - - /** This class handles incoming connections on client ports. * It will create a new User for every valid connection * and assign it a file descriptor. @@ -127,16 +131,10 @@ namespace irc class CoreExport ListenSocketBase : public EventHandler { protected: - /** The creator/owner of this object - */ - InspIRCd* ServerInstance; - /** Socket description (shown in stats p) */ - std::string desc; - - /** Address socket is bound to */ + /** Raw address socket is bound to */ std::string bind_addr; - /** Port socket is bound to */ - int bind_port; + /** Human-readable address/port socket is bound to */ + std::string bind_desc; /** The client address if the most recently connected client. * Should only be used when accepting a new client. @@ -150,52 +148,44 @@ class CoreExport ListenSocketBase : public EventHandler static irc::sockets::sockaddrs server; public: + /** Socket type (client/server) */ + const std::string type; + /** Socket hook (plain/gnutls/openssl/zip) */ + const std::string hook; + /** Port socket is bound to */ + const int bind_port; /** Create a new listening socket */ - ListenSocketBase(InspIRCd* Instance, int port, const std::string &addr); + ListenSocketBase(int port, const std::string &addr, const std::string &type, const std::string &hook); /** Handle an I/O event */ void HandleEvent(EventType et, int errornum = 0); /** Close the socket */ ~ListenSocketBase(); - /** Set descriptive text - */ - void SetDescription(const std::string &description) - { - desc = description; - } - /** Get description for socket - */ - const std::string& GetDescription() - { - return desc; - } - /** Get port number for socket - */ - int GetPort() { return bind_port; } /** Get IP address socket is bound to */ const std::string &GetIP() { return bind_addr; } + const std::string &GetBindDesc() { return bind_desc; } + /** Handles sockets internals crap of a connection, convenience wrapper really */ void AcceptInternal(); /** Called when a new connection has successfully been accepted on this listener. - * @param ipconnectedto The IP address the connection arrived on * @param fd The file descriptor of the new connection - * @param incomingip The IP from which the connection was made */ - virtual void OnAcceptReady(const std::string &ipconnectedto, int fd, const std::string &incomingip) = 0; + virtual void OnAcceptReady(int fd) = 0; }; class CoreExport ClientListenSocket : public ListenSocketBase { - virtual void OnAcceptReady(const std::string &ipconnectedto, int fd, const std::string &incomingip); + virtual void OnAcceptReady(int fd); public: - ClientListenSocket(InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr) { } + ClientListenSocket(int port, const std::string &addr, const std::string &Type, const std::string &Hook) + : ListenSocketBase(port, addr, Type, Hook) { } }; #endif