improve string constant names and log printing

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 4 years ago
parent 8a541b1369
commit c842ae78ad

@ -14,7 +14,7 @@ import (
const (
// Version holds the current version string
Version = "v3.1.7"
Version = "v3.1.8-beta1"
)
var (

@ -1,8 +1,31 @@
package core
// Error string constants
const (
connWriteErrStr = "Conn write error"
connReadErrStr = "Conn read error"
connCloseErrStr = "Conn close error"
listenerBeginErrStr = "Listener begin error"
listenerAcceptErrStr = "Listener accept error"
mutexUpgradeErrStr = "Mutex upgrade fail"
mutexDowngradeErrStr = "Mutex downgrade fail"
fileOpenErrStr = "File open error"
fileStatErrStr = "File stat error"
fileReadErrStr = "File read error"
fileTypeErrStr = "Unsupported file type"
directoryReadErrStr = "Directory read error"
restrictedPathErrStr = "Restricted path"
invalidHostErrStr = "Invalid host"
invalidRequestErrStr = "Invalid request"
cgiStartErrStr = "CGI start error"
cgiExitCodeErrStr = "CGI non-zero exit code"
pgidNotFoundErrStr = "Process unfinished, PGID not found!"
pgidStopErrStr = "Error stopping process group %d: %s"
)
// Log string constants
const (
hostnameBindEmptyStr = "At least one of hostname or bind-addr must be non-empty!"
hostnameBindEmptyStr = "At least one of 'hostname' or 'listen' must be non-empty!"
chrootStr = "Chrooting into dir: %s"
chrootErrStr = "Error chrooting into directory: %s"
@ -61,25 +84,4 @@ const (
signalReceivedStr = "Signal received: %v. Shutting down..."
logOutputErrStr = "Error opening log output %s: %s"
pgidNotFoundErrStr = "Process unfinished, PGID not found!"
pgidStopErrStr = "Error stopping process group %d: %s"
connWriteErrStr = "Conn write error"
connReadErrStr = "Conn read error"
connCloseErrStr = "Conn close error"
listenerBeginErrStr = "Listener begin error"
listenerAcceptErrStr = "Listener accept error"
mutexUpgradeErrStr = "Mutex upgrade fail"
mutexDowngradeErrStr = "Mutex downgrade fail"
fileOpenErrStr = "File open error"
fileStatErrStr = "File stat error"
fileReadErrStr = "File read error"
fileTypeErrStr = "Unsupported file type"
directoryReadErrStr = "Directory read error"
restrictedPathErrStr = "Restricted path"
invalidHostErrStr = "Invalid host"
invalidRequestErrStr = "Invalid request"
cgiStartErrStr = "CGI start error"
cgiExitCodeErrStr = "CGI non-zero exit code"
)

@ -21,14 +21,14 @@ func serve(client *core.Client) {
// We don't accept empty requests
if len(raw) == 0 {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, errors.NewError(core.InvalidRequestErr))
return
}
// Ensure is a valid URL string
if core.HasAsciiControlBytes(raw) {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, errors.NewError(core.InvalidRequestErr))
return
}
@ -36,7 +36,7 @@ func serve(client *core.Client) {
// Get the URL scheme (or error!)
scheme, path, err := core.ParseScheme(raw)
if err != nil {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, err)
return
}
@ -45,7 +45,7 @@ func serve(client *core.Client) {
// were explicitly provided 'gemini'
if scheme != "" {
if scheme != "gemini" {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, errors.NewError(invalidProtocolErr).Extend(scheme))
return
}
@ -57,14 +57,14 @@ func serve(client *core.Client) {
// Parse the URL encoded host info
host, port, err := core.ParseEncodedHost(host)
if err != nil {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, err)
return
}
// Check the host and port are our own (empty port is allowed)
if host != core.Hostname || (port != "" && port != core.Port) {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, errors.NewError(invalidHostPortErr).Extend(host+" "+port))
return
}
@ -72,7 +72,7 @@ func serve(client *core.Client) {
// Parse the encoded URI into path and query components
path, query, err := core.ParseEncodedURI(path)
if err != nil {
client.LogError(clientInvalidRequestStr)
client.LogError(invalidRequestStr, raw)
handleError(client, err)
return
}

@ -30,11 +30,9 @@ const (
// Log string constants
const (
entropyAssertFailStr = "Failed to assert safe source of system entropy exists!"
clientReadFailStr = "Failed to read"
clientInvalidRequestStr = "Invalid request received"
clientRequestParseFailStr = "Failed to parse request"
clientServeFailStr = "Failed to serve: %s"
clientServedStr = "Served: %s"
clientRedirectStr = "Redirect: %s --> %s"
entropyAssertFailStr = "Failed to assert safe source of system entropy exists!"
clientReadFailStr = "Failed to read"
invalidRequestStr = "Invalid request: %s"
clientServeFailStr = "Failed to serve: %s"
clientServedStr = "Served: %s"
)

@ -32,7 +32,7 @@ func serve(client *core.Client) {
// Ensure we've received a valid URL string
if core.HasAsciiControlBytes(raw) {
client.LogError(clientRequestParseFailStr)
client.LogError(invalidRequestStr, raw)
handleError(client, errors.NewError(core.InvalidRequestErr))
return
}
@ -40,7 +40,7 @@ func serve(client *core.Client) {
// Parse the encoded URI into path and query components
path, query, err := core.ParseEncodedURI(raw)
if err != nil {
client.LogError(clientRequestParseFailStr)
client.LogError(invalidRequestStr, raw)
handleError(client, err)
return
}
@ -49,7 +49,7 @@ func serve(client *core.Client) {
if strings.HasPrefix(path, "/URL:") {
raw = raw[5:]
client.Conn().Write(generateHTMLRedirect(raw))
client.LogInfo(clientRedirectFmtStr, raw)
client.LogInfo(gopherRedirectStr, raw)
return
}

@ -13,16 +13,18 @@ const (
errorResponse503 = "503 Service Unavailable"
)
// Log string constants
// Gopher specific error string constants
const (
clientReadFailStr = "Failed to read"
clientRedirectFmtStr = "Redirecting to: %s"
clientRequestParseFailStr = "Failed to parse request"
clientServeFailStr = "Failed to serve: %s"
clientServedStr = "Served: %s"
invalidGophermapErrStr = "Invalid gophermap"
subgophermapIsDirErrStr = "Subgophermap path is dir"
subgophermapSizeErrStr = "Subgophermap size too large"
unknownErrStr = "Unknown error code"
)
// Log string constants
const (
clientReadFailStr = "Failed to read"
gopherRedirectStr = "Redirecting to: %s"
invalidRequestStr = "Invalid request: %s"
clientServeFailStr = "Failed to serve: %s"
clientServedStr = "Served: %s"
)

Loading…
Cancel
Save