diff options
author | bptato <nincsnevem662@gmail.com> | 2024-09-28 17:54:13 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-09-28 17:54:13 +0200 |
commit | 6a0e957e1f2c9f5bea0882efbf2e0494cd5074fa (patch) | |
tree | 3d6206a2bc8676d2fd913c3958e5186fc3375c2b /adapter/protocol | |
parent | 9c257361388f5007871a36eea3abc815a8740d66 (diff) | |
download | chawan-6a0e957e1f2c9f5bea0882efbf2e0494cd5074fa.tar.gz |
loader: clean up connecterror
* allow string values for public errors * remove unused errors * update naming
Diffstat (limited to 'adapter/protocol')
-rw-r--r-- | adapter/protocol/curlerrors.nim | 19 | ||||
-rw-r--r-- | adapter/protocol/file.nim | 9 | ||||
-rw-r--r-- | adapter/protocol/ftp.nim | 6 | ||||
-rw-r--r-- | adapter/protocol/gopher.nim | 5 |
4 files changed, 14 insertions, 25 deletions
diff --git a/adapter/protocol/curlerrors.nim b/adapter/protocol/curlerrors.nim index ce50cd82..8ad05936 100644 --- a/adapter/protocol/curlerrors.nim +++ b/adapter/protocol/curlerrors.nim @@ -1,17 +1,16 @@ import curl -import loader/connecterror -func curlErrorToChaError*(res: CURLcode): ConnectErrorCode = +func curlErrorToChaError*(res: CURLcode): string = return case res - of CURLE_OK: CONNECTION_SUCCESS - of CURLE_URL_MALFORMAT: ERROR_INVALID_URL #TODO should never occur... - of CURLE_COULDNT_CONNECT: ERROR_CONNECTION_REFUSED - of CURLE_COULDNT_RESOLVE_PROXY: ERROR_FAILED_TO_RESOLVE_PROXY - of CURLE_COULDNT_RESOLVE_HOST: ERROR_FAILED_TO_RESOLVE_HOST - of CURLE_PROXY: ERROR_PROXY_REFUSED_TO_CONNECT - else: ERROR_INTERNAL + of CURLE_OK: "" + of CURLE_URL_MALFORMAT: "InvalidURL" #TODO should never occur... + of CURLE_COULDNT_CONNECT: "ConnectionRefused" + of CURLE_COULDNT_RESOLVE_PROXY: "FailedToResolveProxy" + of CURLE_COULDNT_RESOLVE_HOST: "FailedToResolveHost" + of CURLE_PROXY: "ProxyRefusedToConnect" + else: "InternalError" proc getCurlConnectionError*(res: CURLcode): string = - let e = $int(curlErrorToChaError(res)) + let e = curlErrorToChaError(res) let msg = $curl_easy_strerror(res) return "Cha-Control: ConnectionError " & e & " " & msg & "\n" diff --git a/adapter/protocol/file.nim b/adapter/protocol/file.nim index bd2c34a2..bf135180 100644 --- a/adapter/protocol/file.nim +++ b/adapter/protocol/file.nim @@ -4,7 +4,6 @@ import std/times import dirlist -import loader/connecterror import utils/twtstr proc loadDir(path, opath: string) = @@ -79,11 +78,6 @@ proc loadFile(f: File) = break proc main() = - if getEnv("MAPPED_URI_HOST") != "": - let code = int(ERROR_INVALID_URL) - stdout.write("Cha-Control: ConnectionError " & $code & - " cannot use host in file") - return let opath = getEnv("MAPPED_URI_PATH") let path = percentDecode(opath) var f: File @@ -92,7 +86,6 @@ proc main() = elif dirExists(path): loadDir(path, opath) else: - let code = int(ERROR_FILE_NOT_FOUND) - stdout.write("Cha-Control: ConnectionError " & $code) + stdout.write("Cha-Control: ConnectionError FileNotFound") main() diff --git a/adapter/protocol/ftp.nim b/adapter/protocol/ftp.nim index 4484180f..f46f8aee 100644 --- a/adapter/protocol/ftp.nim +++ b/adapter/protocol/ftp.nim @@ -7,7 +7,6 @@ import curlerrors import curlwrap import dirlist -import loader/connecterror import utils/twtstr type FtpHandle = ref object @@ -280,7 +279,7 @@ proc main() = if op.dirmode: let surl = url.get(CURLUPART_URL, cuint(CURLU_PUNY2IDN)) if surl == nil: - stdout.write("Cha-Control: ConnectionError " & $int(ERROR_INVALID_URL)) + stdout.write("Cha-Control: ConnectionError InvalidURL\n") curl_url_cleanup(url) curl_easy_cleanup(curl) return @@ -306,8 +305,7 @@ proc main() = curl.setopt(CURLOPT_PROXY, purl) if getEnv("REQUEST_METHOD") != "GET": # fail - let code = $int(ERROR_INVALID_METHOD) - stdout.write("Cha-Control: ConnectionError " & $code & "\n") + stdout.write("Cha-Control: ConnectionError InvalidMethod\n") else: let res = curl_easy_perform(curl) if res != CURLE_OK: diff --git a/adapter/protocol/gopher.nim b/adapter/protocol/gopher.nim index 14e34b7a..13ade18c 100644 --- a/adapter/protocol/gopher.nim +++ b/adapter/protocol/gopher.nim @@ -9,7 +9,6 @@ import curlwrap import ../gophertypes -import loader/connecterror import utils/twtstr type GopherHandle = ref object @@ -58,7 +57,7 @@ proc main() = let curl = curl_easy_init() doAssert curl != nil if getEnv("REQUEST_METHOD") != "GET": - stdout.write("Cha-Control: ConnectionError " & $int(ERROR_INVALID_METHOD)) + stdout.write("Cha-Control: ConnectionError InvalidMethod") return var path = getEnv("MAPPED_URI_PATH") if path.len < 1: @@ -84,7 +83,7 @@ proc main() = const flags = cuint(CURLU_PUNY2IDN) let surl = url.get(CURLUPART_URL, flags) if surl == nil: - stdout.write("Cha-Control: ConnectionError " & $int(ERROR_INVALID_URL)) + stdout.write("Cha-Control: ConnectionError InvalidURL") else: op.loadSearch($surl) else: |