diff options
-rw-r--r-- | res/mailcap | 6 | ||||
-rw-r--r-- | src/config/config.nim | 20 | ||||
-rw-r--r-- | src/loader/cgi.nim | 9 | ||||
-rw-r--r-- | src/loader/loader.nim | 7 | ||||
-rw-r--r-- | src/main.nim | 6 |
5 files changed, 22 insertions, 26 deletions
diff --git a/res/mailcap b/res/mailcap new file mode 100644 index 00000000..07ac93f7 --- /dev/null +++ b/res/mailcap @@ -0,0 +1,6 @@ +# default mailcap for Chawan + +text/gopher; "$CHA_LIBEXEC_DIR"/gopher2html -u "$MAILCAP_URL"; x-htmloutput +text/gemini; "$CHA_LIBEXEC_DIR"/gmi2html; x-htmloutput +text/markdown; "$CHA_LIBEXEC_DIR"/md2html; x-htmloutput +text/x-ansi; "$CHA_LIBEXEC_DIR"/ansi2html; x-htmloutput diff --git a/src/config/config.nim b/src/config/config.nim index 23762c02..b22b532e 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -595,6 +595,10 @@ proc parseConfigValue(ctx: var ConfigParser; x: var MimeTypes; v: TomlValue; if f != nil: x.parseMimeTypes(f) +const DefaultMailcap = block: + let ss = newStringStream(staticRead"res/mailcap") + parseMailcap(ss).get + proc parseConfigValue(ctx: var ConfigParser; x: var Mailcap; v: TomlValue; k: string) = var paths: seq[ChaPathResolved] @@ -608,21 +612,7 @@ proc parseConfigValue(ctx: var ConfigParser; x: var Mailcap; v: TomlValue; x.add(res.get) else: ctx.warnings.add("Error reading mailcap: " & res.error) - template uq(s: string): string = - ChaPath(s).unquote.get - let defaultCmds = { - "gopher": "${%CHA_LIBEXEC_DIR}/gopher2html -u \\$MAILCAP_URL".uq, - "gemini": "${%CHA_LIBEXEC_DIR}/gmi2html".uq, - "markdown": "${%CHA_LIBEXEC_DIR}/md2html".uq, - "x-ansi":"${%CHA_LIBEXEC_DIR}/ansi2html".uq - } - for (subt, cmd) in defaultCmds: - x.add(MailcapEntry( - mt: "text", - subt: subt, - cmd: cmd, - flags: {HTMLOUTPUT} - )) + x.add(DefaultMailcap) const DefaultURIMethodMap = parseURIMethodMap(staticRead"res/urimethodmap") diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim index 615f956a..f72009d7 100644 --- a/src/loader/cgi.nim +++ b/src/loader/cgi.nim @@ -24,7 +24,7 @@ proc putMappedURL(url: URL) = putEnv("MAPPED_URI_PATH", url.path.serialize()) putEnv("MAPPED_URI_QUERY", url.query.get("")) -proc setupEnv(cmd, scriptName, pathInfo, requestURI, libexecPath, myDir: string; +proc setupEnv(cmd, scriptName, pathInfo, requestURI, myDir: string; request: Request; contentLen: int; prevURL: URL) = let url = request.url putEnv("SERVER_SOFTWARE", "Chawan") @@ -38,7 +38,6 @@ proc setupEnv(cmd, scriptName, pathInfo, requestURI, libexecPath, myDir: string; putEnv("SCRIPT_FILENAME", cmd) putEnv("REQUEST_URI", requestURI) putEnv("REQUEST_METHOD", $request.httpMethod) - putEnv("CHA_LIBEXEC_DIR", libexecPath) var headers = "" for k, v in request.headers: headers &= k & ": " & v & "\r\n" @@ -132,7 +131,7 @@ proc handleLine(handle: LoaderHandle, line: string, headers: Headers) = headers.add(k, v) proc loadCGI*(handle: LoaderHandle; request: Request; cgiDir: seq[string]; - libexecPath: string; prevURL: URL) = + prevURL: URL) = if cgiDir.len == 0: handle.sendResult(ERROR_NO_CGI_DIR) return @@ -211,8 +210,8 @@ proc loadCGI*(handle: LoaderHandle; request: Request; cgiDir: seq[string]; else: closeStdin() # we leave stderr open, so it can be seen in the browser console - setupEnv(cmd, scriptName, pathInfo, requestURI, libexecPath, myDir, request, - contentLen, prevURL) + setupEnv(cmd, scriptName, pathInfo, requestURI, myDir, request, contentLen, + prevURL) discard execl(cstring(cmd), cstring(basename), nil) let code = int(ERROR_FAILED_TO_EXECUTE_CGI_SCRIPT) stdout.write("Cha-Control: ConnectionError " & $code & " " & diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 3b454b4d..17677eb5 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -24,7 +24,6 @@ import std/streams import std/strutils import std/tables -import config/chapath import io/bufwriter import io/posixstream import io/promise @@ -104,7 +103,6 @@ type ssock: ServerSocket alive: bool config: LoaderConfig - libexecPath: string handleMap: Table[int, LoaderHandle] outputMap: Table[int, OutputHandle] selector: Selector[int] @@ -403,7 +401,7 @@ proc loadResource(ctx: LoaderContext; client: ClientData; request: Request; redo = true continue if request.url.scheme == "cgi-bin": - handle.loadCGI(request, ctx.config.cgiDir, ctx.libexecPath, prevurl) + handle.loadCGI(request, ctx.config.cgiDir, prevurl) if handle.istream != nil: ctx.addFd(handle) else: @@ -660,8 +658,7 @@ proc initLoaderContext(fd: cint; config: LoaderConfig): LoaderContext = var ctx = LoaderContext( alive: true, config: config, - selector: newSelector[int](), - libexecPath: ChaPath("${%CHA_LIBEXEC_DIR}").unquote().get + selector: newSelector[int]() ) gctx = ctx #TODO ideally, buffered would be true. Unfortunately this conflicts with diff --git a/src/main.nim b/src/main.nim index f730de5e..ede2f5b8 100644 --- a/src/main.nim +++ b/src/main.nim @@ -1,10 +1,14 @@ import version import server/forkserver +import config/chapath +from std/os import getEnv, putEnv, commandLineParams, getCurrentDir +from types/opt import get + +putEnv("CHA_LIBEXEC_DIR", ChaPath"${%CHA_LIBEXEC_DIR}".unquote().get) let forks = newForkServer() import std/options -import std/os import config/config import io/serversocket |