forked from External/ergo
migrate additional dependencies to ergochat
This commit is contained in:
parent
9dad717c04
commit
7944871eb6
14 changed files with 21 additions and 9 deletions
20
vendor/github.com/ergochat/go-ident/LICENSE
generated
vendored
Normal file
20
vendor/github.com/ergochat/go-ident/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2013 Dominik Honnef
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
19
vendor/github.com/ergochat/go-ident/README.md
generated
vendored
Normal file
19
vendor/github.com/ergochat/go-ident/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# RFC 1413 (Identification Protocol) client
|
||||
|
||||
This package provides a client for the [Identification Protocol](https://tools.ietf.org/html/rfc1413).
|
||||
|
||||
---
|
||||
|
||||
[](https://godoc.org/github.com/DanielOaks/go-ident) [](https://goreportcard.com/report/github.com/DanielOaks/go-ident)
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
go get github.com/DanielOaks/go-ident
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation can be found at [godoc.org](http://godoc.org/github.com/DanielOaks/go-ident).
|
||||
107
vendor/github.com/ergochat/go-ident/client.go
generated
vendored
Normal file
107
vendor/github.com/ergochat/go-ident/client.go
generated
vendored
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
// Package ident implements an RFC 1413 client
|
||||
package ident
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Response is a successful answer to our query to the identd server.
|
||||
type Response struct {
|
||||
OS string
|
||||
Charset string
|
||||
Identifier string
|
||||
}
|
||||
|
||||
// ResponseError indicates that the identd server returned an error rather than an
|
||||
// identifying string.
|
||||
type ResponseError struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
func (e ResponseError) Error() string {
|
||||
return fmt.Sprintf("Ident error: %s", e.Type)
|
||||
}
|
||||
|
||||
// ProtocolError indicates that an error occurred with the protocol itself, that the response
|
||||
// could not be successfully parsed or was malformed.
|
||||
type ProtocolError struct {
|
||||
Line string
|
||||
}
|
||||
|
||||
func (e ProtocolError) Error() string {
|
||||
return fmt.Sprintf("Unexpected response from server: %s", e.Line)
|
||||
}
|
||||
|
||||
// Query makes an Ident query, if timeout is >0 the query is timed out after that many seconds.
|
||||
func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (response Response, err error) {
|
||||
var conn net.Conn
|
||||
if timeout > 0 {
|
||||
conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), timeout)
|
||||
} else {
|
||||
conn, err = net.Dial("tcp", net.JoinHostPort(ip, "113"))
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// stop the ident read after <timeout> seconds
|
||||
if timeout > 0 {
|
||||
conn.SetDeadline(time.Now().Add(timeout))
|
||||
}
|
||||
|
||||
_, err = conn.Write([]byte(fmt.Sprintf("%d, %d", portOnClient, portOnServer) + "\r\n"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r := bufio.NewReaderSize(conn, 1024)
|
||||
respBytes, err := r.ReadSlice('\n')
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp := string(respBytes)
|
||||
|
||||
fields := strings.SplitN(resp, ":", 4)
|
||||
if len(fields) < 3 {
|
||||
return response, ProtocolError{resp}
|
||||
}
|
||||
for i, field := range fields {
|
||||
fields[i] = strings.TrimSpace(field)
|
||||
}
|
||||
|
||||
switch fields[1] {
|
||||
case "USERID":
|
||||
if len(fields) != 4 {
|
||||
return response, ProtocolError{resp}
|
||||
}
|
||||
|
||||
var os, charset string
|
||||
osAndCharset := strings.SplitN(fields[2], ",", 2)
|
||||
if len(osAndCharset) == 2 {
|
||||
os = osAndCharset[0]
|
||||
charset = osAndCharset[1]
|
||||
} else {
|
||||
os = osAndCharset[0]
|
||||
charset = "US-ASCII"
|
||||
}
|
||||
|
||||
return Response{
|
||||
OS: os,
|
||||
Charset: charset,
|
||||
Identifier: fields[3],
|
||||
}, nil
|
||||
case "ERROR":
|
||||
if len(fields) != 3 {
|
||||
return response, ProtocolError{resp}
|
||||
}
|
||||
|
||||
return response, ResponseError{fields[2]}
|
||||
default:
|
||||
err = ProtocolError{resp}
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue