* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
- * $Id: cidr.h,v 1.1 2009/06/20 17:36:52 mrbean_ Exp $
+ * $Id: cidr.h,v 1.2 2009/06/24 17:39:44 mrbean_ Exp $
*/
#ifndef __CIDR_H
-#define __CIDR_H "$Id: cidr.h,v 1.1 2009/06/20 17:36:52 mrbean_ Exp $"
+#define __CIDR_H "$Id: cidr.h,v 1.2 2009/06/24 17:39:44 mrbean_ Exp $"
#include <string>
#include <sys/types.h>
inline const xIP& GetPrefix() const
{ return prefix; }
+ inline const std::string& AsString() const
+ { return str; }
+
bool matches(const std::string& IP) ;
protected:
*/
xIP prefix ;
+ std::string str;
+
private:
bool ExtractMask(const std::string&);
--- /dev/null
+/**
+ * ip.h
+ * This stuff should probably be moved to a static class.
+ * xIP provides mostly utilitarian functionality for IP
+ * addresses.
+ * This class originally created by Orlando Bassotto.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *
+ * $Id: nickUserCidr.h,v 1.1 2009/06/24 17:39:44 mrbean_ Exp $
+ */
+
+#ifndef __NICK_USER_CIDR_H
+#define __NICK_USER_CIDR_H "$Id: nickUserCidr.h,v 1.1 2009/06/24 17:39:44 mrbean_ Exp $"
+
+#include <string>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include "cidr.h"
+
+namespace gnuworld
+{
+
+/**
+ * A utility class that is used to retrieve information about
+ * CIDR addresses.
+ */
+class xNickUserCIDR
+{
+
+public:
+
+ /**
+ * Construct an xNickUserCIDR instance given an address in std::string
+ * format.
+ */
+ xNickUserCIDR( const std::string& nickUserCIDR) ;
+
+ /**
+ * Checks whether or not the CIDR is valid.
+ */
+ inline const bool& GetValid() const
+ { return valid; }
+
+ /**
+ * Retrieve the mask of this CIDR (the part after the /).
+ */
+ inline const unsigned int& GetMask() const
+ { return cidr.GetMask(); }
+
+ /**
+ * Retrieve the prefix of this CIDR (the part before the /).
+ */
+ inline const xIP& GetPrefix() const
+ { return cidr.GetPrefix(); }
+
+ /**
+ * Retrieve the nick
+ */
+ inline const std::string& GetNick() const
+ { return nick; }
+
+ /**
+ * Retrieve the user
+ */
+ inline const std::string& GetUser() const
+ { return user; }
+
+ inline const std::string& AsString() const
+ { return str; }
+
+
+ bool matches(const std::string& IP) ;
+
+protected:
+
+
+ /**
+ * CIDR part
+ */
+ xCIDR cidr;
+
+ /**
+ * The nick
+ */
+ std::string nick ;
+
+ /**
+ * user
+ */
+ std::string user ;
+
+ std::string str ;
+
+ bool valid;
+private:
+
+ bool ExtractNickUser(const std::string&);
+
+} ;
+
+} // namespace gnuworld
+
+#endif
## Process this file with automake to produce Makefile.in
-## $Id: Makefile.am,v 1.30 2009/06/20 17:36:52 mrbean_ Exp $
+## $Id: Makefile.am,v 1.31 2009/06/24 17:39:44 mrbean_ Exp $
lib_LTLIBRARIES = libgnuworldcore.la
libgnuworldcore_la_SOURCES = Channel.cc \
iClient.cc \
iServer.cc \
ip.cc \
+ nickUserCidr.cc \
server.cc \
server_connection.cc \
server_events.cc \
libgnuworldcore_la-UnloadClientTimerHandler.lo \
libgnuworldcore_la-cidr.lo libgnuworldcore_la-client.lo \
libgnuworldcore_la-iClient.lo libgnuworldcore_la-iServer.lo \
- libgnuworldcore_la-ip.lo libgnuworldcore_la-server.lo \
+ libgnuworldcore_la-ip.lo libgnuworldcore_la-nickUserCidr.lo \
+ libgnuworldcore_la-server.lo \
libgnuworldcore_la-server_connection.lo \
libgnuworldcore_la-server_events.lo \
libgnuworldcore_la-server_glines.lo \
iClient.cc \
iServer.cc \
ip.cc \
+ nickUserCidr.cc \
server.cc \
server_connection.cc \
server_events.cc \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-iClient.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-iServer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-ip.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-nickUserCidr.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-server.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-server_connection.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgnuworldcore_la-server_events.Plo@am__quote@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgnuworldcore_la_CXXFLAGS) $(CXXFLAGS) -c -o libgnuworldcore_la-ip.lo `test -f 'ip.cc' || echo '$(srcdir)/'`ip.cc
+libgnuworldcore_la-nickUserCidr.lo: nickUserCidr.cc
+@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgnuworldcore_la_CXXFLAGS) $(CXXFLAGS) -MT libgnuworldcore_la-nickUserCidr.lo -MD -MP -MF $(DEPDIR)/libgnuworldcore_la-nickUserCidr.Tpo -c -o libgnuworldcore_la-nickUserCidr.lo `test -f 'nickUserCidr.cc' || echo '$(srcdir)/'`nickUserCidr.cc
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libgnuworldcore_la-nickUserCidr.Tpo $(DEPDIR)/libgnuworldcore_la-nickUserCidr.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='nickUserCidr.cc' object='libgnuworldcore_la-nickUserCidr.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgnuworldcore_la_CXXFLAGS) $(CXXFLAGS) -c -o libgnuworldcore_la-nickUserCidr.lo `test -f 'nickUserCidr.cc' || echo '$(srcdir)/'`nickUserCidr.cc
+
libgnuworldcore_la-server.lo: server.cc
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgnuworldcore_la_CXXFLAGS) $(CXXFLAGS) -MT libgnuworldcore_la-server.lo -MD -MP -MF $(DEPDIR)/libgnuworldcore_la-server.Tpo -c -o libgnuworldcore_la-server.lo `test -f 'server.cc' || echo '$(srcdir)/'`server.cc
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libgnuworldcore_la-server.Tpo $(DEPDIR)/libgnuworldcore_la-server.Plo
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
- * $Id: cidr.cc,v 1.1 2009/06/20 17:36:52 mrbean_ Exp $
+ * $Id: cidr.cc,v 1.2 2009/06/24 17:39:44 mrbean_ Exp $
*/
#include <string>
#include "StringTokenizer.h"
#include "gnuworld_config.h"
-RCSTAG( "$Id: cidr.cc,v 1.1 2009/06/20 17:36:52 mrbean_ Exp $" ) ;
+RCSTAG( "$Id: cidr.cc,v 1.2 2009/06/24 17:39:44 mrbean_ Exp $" ) ;
namespace gnuworld
{
using std::string ;
-xCIDR::xCIDR( const std::string& IP ) : prefix(0)
+xCIDR::xCIDR( const std::string& IP ) : str(IP), prefix(0)
{
std::size_t pos = IP.find_first_of("/");
if(pos == string::npos || pos == IP.length()) //Failed to find / or its at the end of the string
--- /dev/null
+/**
+ * nickUserCidr.cc
+ * Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
+ * Orlando Bassotto
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *
+ * $Id: nickUserCidr.cc,v 1.1 2009/06/24 17:39:44 mrbean_ Exp $
+ */
+
+#include <string>
+#include <sstream>
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+
+
+#include "nickUserCidr.h"
+#include "misc.h"
+#include "StringTokenizer.h"
+#include "gnuworld_config.h"
+#include "match.h"
+
+RCSTAG( "$Id: nickUserCidr.cc,v 1.1 2009/06/24 17:39:44 mrbean_ Exp $" ) ;
+
+namespace gnuworld
+{
+
+using std::string ;
+
+xNickUserCIDR::xNickUserCIDR( const std::string& nickUserCidr ) : str("") , nick("*"),user("*"),cidr("")
+{
+ StringTokenizer st = StringTokenizer(nickUserCidr,'@');
+ if(st.size() == 1) //No @ , consider everything as a cidr
+ {
+ cidr = xCIDR(nickUserCidr);
+ valid = cidr.GetValid();
+ } else if(st.size() == 2) {
+ ExtractNickUser(st[0]);
+ cidr = xCIDR(st[1]);
+ valid = cidr.GetValid();
+
+ }
+ str = nick + "!" + user + "@" + cidr.AsString();
+
+}
+
+bool xNickUserCIDR::ExtractNickUser(const std::string& nickUser)
+{
+ if(nickUser[0] == '!') //Starts with ! ? user = everything after the !
+ {
+ user = nickUser.substr(1);
+ return true;
+ }
+ StringTokenizer st = StringTokenizer(nickUser,'!');
+ if(st.size() == 1)
+ { //No ! user = everything
+ user = st[0];
+ } else {
+ //We have ! - nick = up til !, user = rest
+ nick = st[0];
+ user = st.assemble(1);
+ }
+ return true;
+}
+bool xNickUserCIDR::matches(const std::string& IP)
+{
+ StringTokenizer st = StringTokenizer(IP,'@');
+ if(st.size() == 1)
+ { // WTF No @ ?!
+ return false;
+ }
+ if(!match(nick+"!"+user,st[0]))
+ { //User and nick match
+ return cidr.matches(st[1]);
+ }
+ return false;
+}
+} // namespace gnuworld