diff --git a/Containerfile.debian b/Containerfile.debian index c5cc596..91c3d81 100644 --- a/Containerfile.debian +++ b/Containerfile.debian @@ -1,18 +1,23 @@ # syntax=docker/dockerfile:1 -ARG GOLANG_VERSION=1.25 +ARG GOLANG_VERSION=1.24 ARG DEBIAN_VERSION=trixie ARG PYTHON_VERSION=3.14 FROM docker.io/library/golang:${GOLANG_VERSION}-${DEBIAN_VERSION} AS gobuilder -RUN --mount=type=bind,source=./libmxclient,target=/build < + + +--- +screenshot: +~/p/m/pygomx (main|✚4) $ docker compose run --rm dev /bin/bash +Container pygomx-dev-run-401f3ed5da9c Creating +Container pygomx-dev-run-401f3ed5da9c Created +root@7c2a56098d3c:/smal# pip install -e . +Obtaining file:///smal + Installing build dependencies ... done + Checking if build backend supports build_editable ... done + Getting requirements to build editable ... done + Preparing editable metadata (pyproject.toml) ... done +Building wheels for collected packages: smal + Building editable for smal (pyproject.toml) ... done + Created wheel for smal: filename=smal-0.0.1-0.editable-py3-none-any.whl size=3038 sha256=11291c3389b4044f1f12f47c2b3885f58139c5665279cab81f3a7488e5a84aeb + Stored in directory: /tmp/pip-ephem-wheel-cache-v8951o8c/wheels/1f/23/eb/fa46f9ff6c1c46feaa27e5ffad7cb966e7aee46d5794e2d15f +Successfully built smal +Installing collected packages: smal +Successfully installed smal-0.0.1 +WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning. +root@7c2a56098d3c:/smal# discoverhs @saces:matrix.org +try to discover mxid: b'@saces:matrix.org' +Attempt to discover 'matrix.org' +b'{"m.homeserver":{"base_url":"https://matrix-client.matrix.org"},"m.identity_server":{"base_url":"https://vector.im"}}' +root@7c2a56098d3c:/smal# diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..bfb6766 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,8 @@ +services: + dev: + build: + context: . + dockerfile: Containerfile.debian + working_dir: /smal + volumes: + - ./smal:/smal:ro diff --git a/libmxclient/go.mod b/libmxclient/go.mod index fe3a8d6..0bdbfcc 100644 --- a/libmxclient/go.mod +++ b/libmxclient/go.mod @@ -1,3 +1,22 @@ module mxclientlib -go 1.23.5 +go 1.24.0 + +require maunium.net/go/mautrix v0.26.1 + +require ( + filippo.io/edwards25519 v1.1.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/rs/zerolog v1.34.0 // indirect + github.com/tidwall/gjson v1.18.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + github.com/tidwall/sjson v1.2.5 // indirect + go.mau.fi/util v0.9.4 // indirect + golang.org/x/crypto v0.46.0 // indirect + golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 // indirect + golang.org/x/net v0.48.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.32.0 // indirect +) diff --git a/libmxclient/go.sum b/libmxclient/go.sum new file mode 100644 index 0000000..382e5d0 --- /dev/null +++ b/libmxclient/go.sum @@ -0,0 +1,42 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= +go.mau.fi/util v0.9.4 h1:gWdUff+K2rCynRPysXalqqQyr2ahkSWaestH6YhSpso= +go.mau.fi/util v0.9.4/go.mod h1:647nVfwUvuhlZFOnro3aRNPmRd2y3iDha9USb8aKSmM= +golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= +golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= +golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 h1:MDfG8Cvcqlt9XXrmEiD4epKn7VJHZO84hejP9Jmp0MM= +golang.org/x/exp v0.0.0-20251209150349-8475f28825e9/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU= +golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= +golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= +golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= +maunium.net/go/mautrix v0.26.1 h1:FWCC1xY5vwJ5ou3duEBjB6w9IIlwfc9el3q3Mju3Dlg= +maunium.net/go/mautrix v0.26.1/go.mod h1:UySSpb8OqXG1sMJ6dDqyzmfcqr2ayZK+KzwqOTAkAOM= diff --git a/libmxclient/mxclient/utils.go b/libmxclient/mxclient/utils.go new file mode 100644 index 0000000..18c9ee6 --- /dev/null +++ b/libmxclient/mxclient/utils.go @@ -0,0 +1,36 @@ +package mxclient + +import ( + "context" + "encoding/json" + "fmt" + + "maunium.net/go/mautrix" + "maunium.net/go/mautrix/id" +) + +func DiscoverHS(ids string) string { + mxid := id.UserID(ids) + + _, hs, err := mxid.Parse() + + if err != nil { + return fmt.Sprintf("ERR: %v", err) + } + + fmt.Printf("Attempt to discover '%s'\n", hs) + + wk, err := mautrix.DiscoverClientAPI(context.Background(), hs) + if err != nil { + return fmt.Sprintf("ERR: %v", err) + } + if wk == nil { + return fmt.Sprintf("No well-known. hs from input: %s", hs) + } + + j, err := json.Marshal(wk) + if err != nil { + return fmt.Sprintf("ERR: %v", err) + } + return string(j) +} diff --git a/libmxclient/mxclientlib.go b/libmxclient/mxclientlib.go index c821090..f8e2152 100644 --- a/libmxclient/mxclientlib.go +++ b/libmxclient/mxclientlib.go @@ -1,7 +1,18 @@ package main +import ( + "mxclientlib/mxclient" +) + import "C" +//export discoverhs +func discoverhs(id *C.char) *C.char { + mxid := C.GoString(id) + result := mxclient.DiscoverHS(mxid) + return C.CString(result) +} + //export hello func hello(name *C.char) *C.char { goName := C.GoString(name) diff --git a/pygomx/build_ffi.py b/pygomx/build_ffi.py index ff9e1d8..0d5efa4 100644 --- a/pygomx/build_ffi.py +++ b/pygomx/build_ffi.py @@ -13,6 +13,7 @@ ffibuilder.set_source( ffibuilder.cdef( csource=""" + extern char* discoverhs(char* p0); extern char* hello(char* p0); """ ) diff --git a/smal/README b/smal/README new file mode 100644 index 0000000..10fdd71 --- /dev/null +++ b/smal/README @@ -0,0 +1,3 @@ + +Simple Matrix Application Library +================================= diff --git a/smal/pyproject.toml b/smal/pyproject.toml new file mode 100644 index 0000000..6d8df0f --- /dev/null +++ b/smal/pyproject.toml @@ -0,0 +1,30 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "smal" +version = "0.0.1" +requires-python = ">=3.11" +description = "smal - simple matrix application library" +authors = [{ name = "saces" }] +license = "AGPL-3.0-only" +readme = "README" +classifiers = [ + "Development Status :: 3 - Alpha", + "Programming Language :: Python", +] + +[tool.setuptools.package-dir] +"pygomx" = "src/pygomx" +"smal" = "src/smal" +"smbl" = "src/smbl" + +[project.urls] +repository = "https://code.c-base.org/saces/pygomx" + +[tool.distutils.egg_info] +egg_base = "/tmp" + +[project.scripts] +discoverhs = "pygomx.mxutils:discoverhs" diff --git a/smal/src/pygomx/mxutils/__init__.py b/smal/src/pygomx/mxutils/__init__.py new file mode 100644 index 0000000..b84a711 --- /dev/null +++ b/smal/src/pygomx/mxutils/__init__.py @@ -0,0 +1 @@ +from .discoverhs import discoverhs diff --git a/smal/src/pygomx/mxutils/discoverhs.py b/smal/src/pygomx/mxutils/discoverhs.py new file mode 100644 index 0000000..5e8e953 --- /dev/null +++ b/smal/src/pygomx/mxutils/discoverhs.py @@ -0,0 +1,16 @@ +import sys +from _pygomx import lib, ffi + + +def discoverhs(): + if len(sys.argv) != 2: + print("usage: ", sys.argv[0], " matrixid") + return 1 + + mxid = sys.argv[1].encode(encoding="utf-8") + + print("try to discover from: ", mxid) + + r = lib.discoverhs(mxid) + result = ffi.string(r) + print(result) diff --git a/smal/src/smal/__init__.py b/smal/src/smal/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smal/src/smbl/__init__.py b/smal/src/smbl/__init__.py new file mode 100644 index 0000000..e69de29