From bb773e10b990d40cb9f3a2c291ed17e3655e7f55 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 10 Oct 2023 09:04:59 +0100 Subject: [PATCH] Adjust to Syndicate API --- src/open.nim | 30 +++++++++++++++++++----------- src/uri_runner.nim | 16 ++++++++-------- syndicated_open.nimble | 2 +- uri_runner.pr | 2 -- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/open.nim b/src/open.nim index 4b161c5..b27e3f5 100644 --- a/src/open.nim +++ b/src/open.nim @@ -2,10 +2,20 @@ # SPDX-License-Identifier: Unlicense import std/[asyncdispatch, os, uri] -import preserves, syndicate, syndicate/capabilities +import preserves, syndicate, syndicate/relays, syndicate/capabilities import ./protocol, ./common -proc publishUri(turn: var Turn; ds: Ref) = +proc unixSocketPath: Unix = + result.path = getEnv("SYNDICATE_SOCK") + if result.path == "": + result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace" + +proc envStep: Assertion = + var s = getEnv("SYNDICATE_STEP") + if s != "": parsePreserves(s, Cap) + else: capabilities.mint().toPreserve(Cap) + +proc publishUri(turn: var Turn; ds: Cap) = for arg in commandLineParams(): if fileExists(arg): message(turn, ds, Open(uri: protocol.Uri( @@ -14,14 +24,12 @@ proc publishUri(turn: var Turn; ds: Ref) = message(turn, ds, initRecord("open", arg.parseUri.toPreserve)) stop(turn) -proc unixSocketPath: Unix = - result.path = getEnv("SYNDICATE_SOCK") - if result.path == "": - result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace" +proc main = + let step = envStep() + discard bootDataspace("open") do (root: Cap; turn: var Turn): + connect(turn, unixSocketPath(), step, publishUri) -discard bootDataspace("open") do (root: Ref; turn: var Turn): - let cap = mint().toPreserve(Ref) - connect(turn, unixSocketPath(), cap, publishUri) + for i in 0..4: poll(20) + # A hack to exit -for i in 0..4: poll(20) - # A hack to exit +main() diff --git a/src/uri_runner.nim b/src/uri_runner.nim index 9b271c3..893d013 100644 --- a/src/uri_runner.nim +++ b/src/uri_runner.nim @@ -2,29 +2,29 @@ # SPDX-License-Identifier: Unlicense import std/[re, tables, uri] -import preserves, syndicate, syndicate/patterns +import preserves, syndicate, syndicate/relays, syndicate/patterns import ./protocol, ./common # importing std/re doesn't actually link against PCRE {.passC: staticExec("pkg-config --cflags libpcre").} {.passL: staticExec("pkg-config --libs libpcre").} -type RegexAction = tuple[regex: Regex, entity: Ref, action: Assertion] +type RegexAction = tuple[regex: Regex, entity: Cap, action: Assertion] -proc rewrite(result: var Assertion; uri: string; regex: Regex) = - proc op(pr: var Assertion) = +proc rewrite(result: var Assertion; uri: string; regex: Regex) {.gcsafe.} = + proc op(pr: var Assertion) {.gcsafe.} = if pr.isString: pr.string = replacef(uri, regex, pr.string) apply(result, op) -runActor("main") do (root: Ref; turn: var Turn): +runActor("main") do (root: Cap; turn: var Turn): connectStdio(root, turn) - var handlers: Table[Handle, RegexAction] - during(turn, root, ?UriRunnerConfig) do (handlerspace: Ref, urispace: Ref): + let handlers = newTable[Handle, RegexAction]() + during(turn, root, ?UriRunnerConfig) do (handlerspace: Cap, urispace: Cap): during(turn, handlerspace, dropType(ActionHandler)) do: - during(turn, handlerspace, ?ActionHandler) do (pat: string; entity: Ref; act: Assertion): + during(turn, handlerspace, ?ActionHandler) do (pat: string; entity: Cap; act: Assertion): # `duringHandle` is a symbol exposed by the `during` macro handlers[duringHandle] = (re(pat, {reIgnoreCase, reStudy}), entity, act,) do: diff --git a/syndicated_open.nimble b/syndicated_open.nimble index 687a3c6..6aae95a 100644 --- a/syndicated_open.nimble +++ b/syndicated_open.nimble @@ -1,6 +1,6 @@ # Package -version = "20230630" +version = "20231010" author = "Emery" description = "Syndicated open command" license = "Unlicense" diff --git a/uri_runner.pr b/uri_runner.pr index b5ae443..ebfeba4 100644 --- a/uri_runner.pr +++ b/uri_runner.pr @@ -1,5 +1,3 @@ -> - ; configure the daemon when it is built ; (this is an artifact of the author's build system) ? [