summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-10 00:36:07 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-10 00:36:07 +0000
commitd7336f351d9740fc4bfc1289c2b090a0f272d201 (patch)
tree6146e8b695945f64503050968c3d83c3aa34cfd6 /src
parentad3c37e38c6c170c1f7cc3232db748ebdc62aa94 (diff)
Move the socket functions like insp_ntoa into their own namespace. They arent really sensible to put into a class, but namespacing them out discourages developers from directly using them without explicitly saing 'using irc::sockets::BindPorts' or whatever first. Some functions such as insp_ntoa are already 'exposed' by headers that use them so 'using irc::sockets::inet_ntoa' isnt required.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4828 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp2
-rw-r--r--src/dns.cpp7
-rw-r--r--src/hashcomp.cpp1
-rw-r--r--src/inspircd.cpp6
-rw-r--r--src/inspsocket.cpp4
-rw-r--r--src/modules/m_spanningtree.cpp2
-rw-r--r--src/socket.cpp25
-rw-r--r--src/wildcard.cpp2
8 files changed, 39 insertions, 10 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index c8ecdaf39..0b712ca6c 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -34,6 +34,8 @@ extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
+using irc::sockets::BindPorts;
+
std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
ServerConfig::ServerConfig()
diff --git a/src/dns.cpp b/src/dns.cpp
index 9bc81e453..b67fef8d9 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -42,6 +42,13 @@ using namespace std;
#include "inspircd_config.h"
#include "socketengine.h"
#include "configreader.h"
+#include "socket.h"
+
+using namespace std;
+using irc::sockets::insp_sockaddr;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_aton;
/* Master file descriptor */
int DNS::MasterSocket;
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index bfbabfde9..278ea0044 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -58,6 +58,7 @@ extern const char lowermap[255];
******************************************************/
using namespace std;
+using namespace irc::sockets;
size_t nspace::hash<insp_inaddr>::operator()(const insp_inaddr &a) const
{
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index a4b6181ab..aaf20062f 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -65,6 +65,12 @@
#include "typedefs.h"
#include "command_parse.h"
+using irc::sockets::BindPorts;
+using irc::sockets::NonBlocking;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_sockaddr;
+
InspIRCd* ServerInstance = NULL;
extern ModuleList modules;
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 6a0fbc556..187a5265d 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -28,6 +28,10 @@
#include "message.h"
#include "inspircd.h"
+using irc::sockets::BindSocket;
+using irc::sockets::OpenTCPSocket;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_sockaddr;
extern time_t TIME;
extern Server* MyServer;
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 003a4868d..72ae322f6 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -65,6 +65,8 @@ using namespace std;
* we can resort to recursion to walk the tree structure.
*/
+using irc::sockets::MatchCIDR;
+
class ModuleSpanningTree;
static ModuleSpanningTree* TreeProtocolModule;
diff --git a/src/socket.cpp b/src/socket.cpp
index 693685428..0f84912de 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -27,6 +27,9 @@
extern InspIRCd* ServerInstance;
extern time_t TIME;
+using namespace std;
+using namespace irc::sockets;
+
/* Used when comparing CIDR masks for the modulus bits left over.
* A lot of ircd's seem to do this:
* ((-1) << (8 - (mask % 8)))
@@ -43,7 +46,7 @@ const char inverted_bits[8] = { 0x00, /* 00000000 - 0 bits - never actually used
};
/* Match raw bytes using CIDR bit matching, used by higher level MatchCIDR() */
-bool MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits)
+bool irc::sockets::MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits)
{
unsigned int modulus = mask_bits % 8; /* Number of whole bytes in the mask */
unsigned int divisor = mask_bits / 8; /* Remaining bits in the mask after whole bytes are dealt with */
@@ -63,7 +66,7 @@ bool MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mas
}
/* Match CIDR, but dont attempt to match() against leading *!*@ sections */
-bool MatchCIDR(const char* address, const char* cidr_mask)
+bool irc::sockets::MatchCIDR(const char* address, const char* cidr_mask)
{
return MatchCIDR(address, cidr_mask, false);
}
@@ -75,7 +78,7 @@ bool MatchCIDR(const char* address, const char* cidr_mask)
* This will also attempt to match any leading usernames or nicknames on the mask, using
* match(), when match_with_username is true.
*/
-bool MatchCIDR(const char* address, const char* cidr_mask, bool match_with_username)
+bool irc::sockets::MatchCIDR(const char* address, const char* cidr_mask, bool match_with_username)
{
unsigned char addr_raw[16];
unsigned char mask_raw[16];
@@ -208,13 +211,13 @@ bool MatchCIDR(const char* address, const char* cidr_mask, bool match_with_usern
return MatchCIDRBits(addr_raw, mask_raw, bits);
}
-inline void Blocking(int s)
+inline void irc::sockets::Blocking(int s)
{
int flags = fcntl(s, F_GETFL, 0);
fcntl(s, F_SETFL, flags ^ O_NONBLOCK);
}
-inline void NonBlocking(int s)
+inline void irc::sockets::NonBlocking(int s)
{
int flags = fcntl(s, F_GETFL, 0);
fcntl(s, F_SETFL, flags | O_NONBLOCK);
@@ -225,7 +228,7 @@ inline void NonBlocking(int s)
* It can only bind to IP addresses, if you wish to bind to hostnames
* you should first resolve them using class 'Resolver'.
*/
-bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr)
+bool irc::sockets::BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr)
{
memset(&server,0,sizeof(server));
insp_inaddr addy;
@@ -287,7 +290,7 @@ bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port
// Open a TCP Socket
-int OpenTCPSocket()
+int irc::sockets::OpenTCPSocket()
{
int sockfd;
int on = 1;
@@ -309,6 +312,7 @@ int OpenTCPSocket()
}
}
+/* XXX: Probably belongs in class InspIRCd */
bool HasPort(int port, char* addr)
{
ServerConfig* Config = ServerInstance->Config;
@@ -322,7 +326,8 @@ bool HasPort(int port, char* addr)
return false;
}
-int BindPorts(bool bail)
+/* XXX: Probably belongs in class InspIRCd */
+int irc::sockets::BindPorts(bool bail)
{
char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
insp_sockaddr client, server;
@@ -442,14 +447,14 @@ int BindPorts(bool bail)
return BoundPortCount;
}
-const char* insp_ntoa(insp_inaddr n)
+const char* irc::sockets::insp_ntoa(insp_inaddr n)
{
static char buf[1024];
inet_ntop(AF_FAMILY, &n, buf, sizeof(buf));
return buf;
}
-int insp_aton(const char* a, insp_inaddr* n)
+int irc::sockets::insp_aton(const char* a, insp_inaddr* n)
{
return inet_pton(AF_FAMILY, a, n);
}
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index e626f2aa2..6b84ef5b3 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -22,6 +22,8 @@ using namespace std;
#include "helperfuncs.h"
#include "inspstring.h"
+using irc::sockets::MatchCIDR;
+
extern char lowermap[255];
// Wed 27 Apr 2005 - Brain