3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00

Split utils out to a separate subpackage

This commit is contained in:
Daniel Oaks 2017-10-05 23:47:43 +10:00
parent 4aa52956e5
commit 207c1074df
7 changed files with 20 additions and 16 deletions

View File

@ -21,6 +21,7 @@ import (
ident "github.com/oragono/go-ident"
"github.com/oragono/oragono/irc/caps"
"github.com/oragono/oragono/irc/sno"
"github.com/oragono/oragono/irc/utils"
)
const (
@ -153,7 +154,7 @@ func (client *Client) IP() net.IP {
return net.ParseIP(client.proxiedIP)
}
return net.ParseIP(IPString(client.socket.conn.RemoteAddr()))
return net.ParseIP(utils.IPString(client.socket.conn.RemoteAddr()))
}
// IPString returns the IP address of this client as a string.
@ -197,7 +198,7 @@ func (client *Client) run() {
// Set the hostname for this client
// (may be overridden by a later PROXY command from stunnel)
client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
client.rawHostname = utils.AddrLookupHostname(client.socket.conn.RemoteAddr())
for {
line, err = client.socket.Read()
@ -451,7 +452,7 @@ func (client *Client) AllNickmasks() []string {
masks = append(masks, mask)
}
mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, IPString(client.socket.conn.RemoteAddr())))
mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", client.nick, client.username, utils.IPString(client.socket.conn.RemoteAddr())))
if err == nil && mask2 != mask {
masks = append(masks, mask2)
}

View File

@ -16,6 +16,7 @@ import (
"github.com/oragono/oragono/irc/custime"
"github.com/oragono/oragono/irc/logger"
"github.com/oragono/oragono/irc/utils"
"code.cloudfoundry.org/bytefmt"
@ -383,7 +384,7 @@ func LoadConfig(filename string) (config *Config, err error) {
if config.Server.Name == "" {
return nil, errors.New("Server name missing")
}
if !IsHostname(config.Server.Name) {
if !utils.IsHostname(config.Server.Name) {
return nil, errors.New("Server name must match the format of a hostname")
}
if config.Datastore.Path == "" {

View File

@ -10,6 +10,7 @@ import (
"sync"
"github.com/goshuirc/irc-go/ircmsg"
"github.com/oragono/oragono/irc/utils"
)
// MonitorManager keeps track of who's monitoring which nicks.
@ -218,7 +219,7 @@ func monitorListHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
nickList = append(nickList, replynick)
}
for _, line := range argsToStrings(maxLastArgLength, nickList, ",") {
for _, line := range utils.ArgsToStrings(maxLastArgLength, nickList, ",") {
client.Send(nil, server.name, RPL_MONLIST, client.getNick(), line)
}
@ -243,12 +244,12 @@ func monitorStatusHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
}
if len(online) > 0 {
for _, line := range argsToStrings(maxLastArgLength, online, ",") {
for _, line := range utils.ArgsToStrings(maxLastArgLength, online, ",") {
client.Send(nil, server.name, RPL_MONONLINE, client.getNick(), line)
}
}
if len(offline) > 0 {
for _, line := range argsToStrings(maxLastArgLength, offline, ",") {
for _, line := range utils.ArgsToStrings(maxLastArgLength, offline, ",") {
client.Send(nil, server.name, RPL_MONOFFLINE, client.getNick(), line)
}
}

View File

@ -27,6 +27,7 @@ import (
"github.com/oragono/oragono/irc/isupport"
"github.com/oragono/oragono/irc/logger"
"github.com/oragono/oragono/irc/sno"
"github.com/oragono/oragono/irc/utils"
"github.com/tidwall/buntdb"
)
@ -267,7 +268,7 @@ func (server *Server) Run() {
case conn := <-server.newConns:
// check IP address
ipaddr := net.ParseIP(IPString(conn.Conn.RemoteAddr()))
ipaddr := net.ParseIP(utils.IPString(conn.Conn.RemoteAddr()))
if ipaddr == nil {
conn.Conn.Write([]byte(couldNotParseIPMsg))
conn.Conn.Close()
@ -1034,7 +1035,7 @@ func (client *Client) getWhoisOf(target *Client) {
client.Send(nil, client.server.name, RPL_WHOISOPERATOR, client.nick, target.nick, target.whoisLine)
}
if client.flags[Operator] || client == target {
client.Send(nil, client.server.name, RPL_WHOISACTUALLY, client.nick, target.nick, fmt.Sprintf("%s@%s", target.username, LookupHostname(target.IPString())), target.IPString(), "Actual user@host, Actual IP")
client.Send(nil, client.server.name, RPL_WHOISACTUALLY, client.nick, target.nick, fmt.Sprintf("%s@%s", target.username, utils.LookupHostname(target.IPString())), target.IPString(), "Actual user@host, Actual IP")
}
if target.flags[TLS] {
client.Send(nil, client.server.name, RPL_WHOISSECURE, client.nick, target.nick, "is using a secure connection")
@ -2177,7 +2178,7 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
return false
}
clientAddress := IPString(client.socket.conn.RemoteAddr())
clientAddress := utils.IPString(client.socket.conn.RemoteAddr())
clientHostname := client.hostname
for _, address := range server.proxyAllowedFrom {
if clientHostname == address || clientAddress == address {
@ -2198,7 +2199,7 @@ func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// override the client's regular IP
client.proxiedIP = msg.Params[1]
client.rawHostname = LookupHostname(msg.Params[1])
client.rawHostname = utils.LookupHostname(msg.Params[1])
client.hostname = client.rawHostname
return false
}

View File

@ -1,11 +1,11 @@
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package irc
package utils
// argsToStrings takes the arguments and splits them into a series of strings,
// ArgsToStrings takes the arguments and splits them into a series of strings,
// each argument separated by delim and each string bounded by maxLength.
func argsToStrings(maxLength int, arguments []string, delim string) []string {
func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
var messages []string
var buffer string

View File

@ -2,7 +2,7 @@
// Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package irc
package utils
import (
"net"

View File

@ -2,7 +2,7 @@
// Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package irc
package utils
import "testing"