mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 00:14:07 +01:00
ircd: Minor cleanup of rfc1459 header.
This commit is contained in:
parent
d3be7129cf
commit
ed0760ef8e
1 changed files with 87 additions and 80 deletions
|
@ -1,27 +1,21 @@
|
||||||
/*
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||||
* charybdis: 21st Century IRC++d
|
// Copyright (C) 2016-2018 Jason Volk
|
||||||
* rfc1459.h: RFC1459 Specification API
|
//
|
||||||
*
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* Copyright (C) 2016 Charybdis Development Team
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
* Copyright (C) 2016 Jason Volk <jason@zemos.net>
|
// copyright notice and this permission notice is present in all copies.
|
||||||
*
|
//
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* copyright notice and this permission notice is present in all copies.
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
*
|
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
||||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#define HAVE_IRCD_RFC1459_H
|
#define HAVE_IRCD_RFC1459_H
|
||||||
|
@ -29,13 +23,49 @@
|
||||||
/// Legacy IRC grammars & tools
|
/// Legacy IRC grammars & tools
|
||||||
namespace ircd::rfc1459
|
namespace ircd::rfc1459
|
||||||
{
|
{
|
||||||
|
struct nick;
|
||||||
|
struct user;
|
||||||
|
struct host;
|
||||||
|
struct cmd;
|
||||||
|
struct parv;
|
||||||
|
struct pfx;
|
||||||
|
struct line;
|
||||||
|
|
||||||
IRCD_EXCEPTION(ircd::error, error)
|
IRCD_EXCEPTION(ircd::error, error)
|
||||||
IRCD_EXCEPTION(error, syntax_error)
|
IRCD_EXCEPTION(error, syntax_error)
|
||||||
|
|
||||||
namespace character
|
std::ostream &operator<<(std::ostream &, const pfx &);
|
||||||
|
std::ostream &operator<<(std::ostream &, const cmd &);
|
||||||
|
std::ostream &operator<<(std::ostream &, const parv &);
|
||||||
|
std::ostream &operator<<(std::ostream &, const line &); // unterminated
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ircd::rfc1459::character
|
||||||
{
|
{
|
||||||
enum attr
|
enum attr :uint;
|
||||||
|
using attr_t = std::underlying_type<attr>::type;
|
||||||
|
|
||||||
|
extern const std::array<attr_t, 256> attrs;
|
||||||
|
extern const std::array<unsigned char, 256> tolower_tab;
|
||||||
|
extern const std::array<unsigned char, 256> toupper_tab;
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
bool is(const uint8_t &c, const attr &attr);
|
||||||
|
|
||||||
|
// Transforms
|
||||||
|
const uint8_t &tolower(const uint8_t &c);
|
||||||
|
const uint8_t &toupper(const uint8_t &c);
|
||||||
|
|
||||||
|
// Get all characters for an attribute mask
|
||||||
|
size_t gather(const attr &attr, uint8_t *const &buf, const size_t &max);
|
||||||
|
std::string gather(const attr &attr);
|
||||||
|
|
||||||
|
// Like gather() but with special considerations for boost::spirit's char_()
|
||||||
|
size_t charset(const attr &attr, uint8_t *const &buf, const size_t &max);
|
||||||
|
std::string charset(const attr &attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ircd::rfc1459::character::attr
|
||||||
:uint
|
:uint
|
||||||
{
|
{
|
||||||
PRINT = 0x00000001,
|
PRINT = 0x00000001,
|
||||||
|
@ -58,27 +88,10 @@ namespace character
|
||||||
FCHAN = 0x00020000, // a 'fake' channel char
|
FCHAN = 0x00020000, // a 'fake' channel char
|
||||||
};
|
};
|
||||||
|
|
||||||
using attr_t = std::underlying_type<attr>::type;
|
|
||||||
|
|
||||||
extern const std::array<attr_t, 256> attrs;
|
namespace ircd::rfc1459 {
|
||||||
extern const std::array<unsigned char, 256> tolower_tab;
|
|
||||||
extern const std::array<unsigned char, 256> toupper_tab;
|
|
||||||
|
|
||||||
// Tests
|
struct less;
|
||||||
bool is(const uint8_t &c, const attr &attr);
|
|
||||||
|
|
||||||
// Transforms
|
|
||||||
const uint8_t &tolower(const uint8_t &c);
|
|
||||||
const uint8_t &toupper(const uint8_t &c);
|
|
||||||
|
|
||||||
// Get all characters for an attribute mask
|
|
||||||
size_t gather(const attr &attr, uint8_t *const &buf, const size_t &max);
|
|
||||||
std::string gather(const attr &attr);
|
|
||||||
|
|
||||||
// Like gather() but with special considerations for boost::spirit's char_()
|
|
||||||
size_t charset(const attr &attr, uint8_t *const &buf, const size_t &max);
|
|
||||||
std::string charset(const attr &attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
using character::is;
|
using character::is;
|
||||||
using character::toupper;
|
using character::toupper;
|
||||||
|
@ -114,44 +127,39 @@ inline bool is_xdigit(const char &c)
|
||||||
return is_digit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F');
|
return is_digit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F');
|
||||||
}
|
}
|
||||||
|
|
||||||
struct less
|
} // namespace ircd::rfc1459
|
||||||
{
|
|
||||||
bool operator()(const char *const &a, const char *const &b) const;
|
|
||||||
bool operator()(const std::string &a, const std::string &b) const;
|
|
||||||
bool operator()(const std::string_view &a, const std::string_view &b) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct nick
|
struct ircd::rfc1459::nick
|
||||||
:string_view
|
:string_view
|
||||||
{
|
{
|
||||||
using string_view::string_view;
|
using string_view::string_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct user
|
struct ircd::rfc1459::user
|
||||||
:string_view
|
:string_view
|
||||||
{
|
{
|
||||||
using string_view::string_view;
|
using string_view::string_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct host
|
struct ircd::rfc1459::host
|
||||||
:string_view
|
:string_view
|
||||||
{
|
{
|
||||||
using string_view::string_view;
|
using string_view::string_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd
|
struct ircd::rfc1459::cmd
|
||||||
:string_view
|
:string_view
|
||||||
{
|
{
|
||||||
using string_view::string_view;
|
using string_view::string_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct parv
|
struct ircd::rfc1459::parv
|
||||||
:std::vector<string_view>
|
:std::vector<string_view>
|
||||||
{
|
{
|
||||||
using std::vector<string_view>::vector;
|
using std::vector<string_view>::vector;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pfx
|
struct ircd::rfc1459::pfx
|
||||||
{
|
{
|
||||||
struct nick nick;
|
struct nick nick;
|
||||||
struct user user;
|
struct user user;
|
||||||
|
@ -160,7 +168,7 @@ struct pfx
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct line
|
struct ircd::rfc1459::line
|
||||||
{
|
{
|
||||||
struct pfx pfx;
|
struct pfx pfx;
|
||||||
struct cmd cmd;
|
struct cmd cmd;
|
||||||
|
@ -174,14 +182,15 @@ struct line
|
||||||
line() = default;
|
line() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &, const pfx &);
|
struct ircd::rfc1459::less
|
||||||
std::ostream &operator<<(std::ostream &, const cmd &);
|
{
|
||||||
std::ostream &operator<<(std::ostream &, const parv &);
|
bool operator()(const char *const &a, const char *const &b) const;
|
||||||
std::ostream &operator<<(std::ostream &, const line &); // unterminated
|
bool operator()(const std::string &a, const std::string &b) const;
|
||||||
|
bool operator()(const std::string_view &a, const std::string_view &b) const;
|
||||||
|
};
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
less::operator()(const std::string_view &a,
|
ircd::rfc1459::less::operator()(const std::string_view &a,
|
||||||
const std::string_view &b)
|
const std::string_view &b)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -193,7 +202,7 @@ const
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
less::operator()(const std::string &a,
|
ircd::rfc1459::less::operator()(const std::string &a,
|
||||||
const std::string &b)
|
const std::string &b)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -205,7 +214,7 @@ const
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
less::operator()(const char *const &a,
|
ircd::rfc1459::less::operator()(const char *const &a,
|
||||||
const char *const &b)
|
const char *const &b)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -217,22 +226,20 @@ const
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const uint8_t &
|
inline const uint8_t &
|
||||||
character::tolower(const uint8_t &c)
|
ircd::rfc1459::character::tolower(const uint8_t &c)
|
||||||
{
|
{
|
||||||
return tolower_tab[c];
|
return tolower_tab[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const uint8_t &
|
inline const uint8_t &
|
||||||
character::toupper(const uint8_t &c)
|
ircd::rfc1459::character::toupper(const uint8_t &c)
|
||||||
{
|
{
|
||||||
return toupper_tab[c];
|
return toupper_tab[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
character::is(const uint8_t &c,
|
ircd::rfc1459::character::is(const uint8_t &c,
|
||||||
const attr &attr)
|
const attr &attr)
|
||||||
{
|
{
|
||||||
return (attrs[c] & attr) == attr;
|
return (attrs[c] & attr) == attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue