forked from Telodendria/Telodendria
Compare commits
25 commits
master
...
setup-ci-w
Author | SHA1 | Date | |
---|---|---|---|
6907169d5f | |||
9b77612c5e | |||
247510c634 | |||
cd321bee14 | |||
33cec5adfd | |||
1dc19ac070 | |||
01fa950dc6 | |||
b488943e10 | |||
089942b8ef | |||
d63faeb0de | |||
3e1ff735ed | |||
b60e45538b | |||
9139661046 | |||
8260fd8bad | |||
87febe92be | |||
dc5e95e4c0 | |||
4674621637 | |||
5295e0295b | |||
cba882dae5 | |||
e4952a8f33 | |||
a3eb5b8aa2 | |||
673945fe9f | |||
c326080f93 | |||
1e6e48e181 | |||
795b465e62 |
8 changed files with 324 additions and 61 deletions
22
.gitea/actions/setup-build/action.yml
Normal file
22
.gitea/actions/setup-build/action.yml
Normal file
|
@ -0,0 +1,22 @@
|
|||
name: Setup a basic build environment
|
||||
description: Setup a basic build environment with a proper SSL library
|
||||
|
||||
inputs:
|
||||
compiler:
|
||||
description: Compiler used for setting up everything
|
||||
required: false
|
||||
default: gcc
|
||||
ssl:
|
||||
description: SSL library used for Cytoplasm later on
|
||||
required: false
|
||||
default: openssl
|
||||
|
||||
outputs:
|
||||
compiler:
|
||||
description: Compiler binary
|
||||
value: '${{ steps.install.outputs.compiler }}'
|
||||
|
||||
runs:
|
||||
- run: 'echo We are on "${{runner.os}}", requested "${{inputs.compiler}}" as CC'
|
||||
- run: 'echo hi && setup "${{ runner.os }}" "${{inputs.compiler}}" "${{inputs.ssl}}"'
|
||||
shell: bash
|
60
.gitea/actions/setup-build/setup
Executable file
60
.gitea/actions/setup-build/setup
Executable file
|
@ -0,0 +1,60 @@
|
|||
#!/bin/bash
|
||||
|
||||
COMPILER=$2
|
||||
SSL=$3
|
||||
|
||||
DISTRO=$(grep -E '^NAME=' /etc/os-release |
|
||||
cut -d'=' -f2 |
|
||||
tr -d '"')
|
||||
|
||||
# Installs a package using the native OS's package manager.
|
||||
install_pkg() {
|
||||
case $DISTRO in
|
||||
"Ubuntu")
|
||||
"Debian GNU/Linux" )
|
||||
apt install -y $1
|
||||
;;
|
||||
"Arch Linux" )
|
||||
pacman -Syu --noconfirm $1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_compiler() {
|
||||
echo '::group::Setting up a compiler'
|
||||
case $DISTRO in
|
||||
"Ubuntu" )
|
||||
"Debian GNU/Linux" )
|
||||
install_pkg build-essential
|
||||
[ $COMPILER = 'clang' ] && install_pkg clang
|
||||
|
||||
CC=gcc
|
||||
[ $COMPILER = 'clang' ] && CC=clang
|
||||
;;
|
||||
"Arch Linux" )
|
||||
install_pkg $COMPILER make
|
||||
CC=gcc
|
||||
[ $COMPILER = 'clang' ] && CC=clang
|
||||
esac
|
||||
echo '::endgroup::'
|
||||
}
|
||||
install_ssl() {
|
||||
echo '::group::Setting up SSL'
|
||||
case $DISTRO in
|
||||
"Ubuntu" )
|
||||
"Debian GNU/Linux" )
|
||||
# Doesn't seem like Debian got LibreSSL
|
||||
[ $SSL = 'libressl' ] && echo "::error ::LibreSSL is not on Debian"
|
||||
install_pkg openssl
|
||||
;;
|
||||
"Arch Linux" )
|
||||
install_pkg $SSL
|
||||
esac
|
||||
echo '::endgroup::'
|
||||
}
|
||||
|
||||
# Install the compiler and SSL
|
||||
install_compiler
|
||||
install_ssl
|
||||
|
||||
echo "compiler=$CC" >> "$GITHUB_OUTPUT"
|
28
.gitea/workflows/test-push.yaml
Normal file
28
.gitea/workflows/test-push.yaml
Normal file
|
@ -0,0 +1,28 @@
|
|||
name: Testing pushed commits
|
||||
run-name: "Testing pushed changes (HEAD@${{ github.head_ref }}) on ${{ runner.os }}"
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
# Compiles out everything.
|
||||
setup-repo:
|
||||
# TODO: More architectures
|
||||
runs-on: debian
|
||||
steps:
|
||||
# Checks out Telodendria, and setups a basic build environment.
|
||||
- name: Checking out Telodendria
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup build environment
|
||||
uses: https://git.freetards.xyz/lda/ci-setup-cc-ssl@master
|
||||
with:
|
||||
compiler: gcc
|
||||
ssl: openssl
|
||||
# TODO: Implement all of this
|
||||
# Compile out Cytoplasm
|
||||
#- name: Compiles Cytoplasm
|
||||
# uses: ./.gitea/actions/build-latest-cytoplasm
|
||||
|
||||
# Finally, builds out Telodendria with everything.
|
||||
#- name: Compiles Telodendria
|
||||
# uses: ./.gitea/actions/build-telodendria
|
||||
|
||||
|
13
Schema/UserDirectoryRequest.json
Normal file
13
Schema/UserDirectoryRequest.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"header": "Schema\/UserDirectoryRequest.h",
|
||||
"types": {
|
||||
"UserDirectoryRequest": {
|
||||
"fields": {
|
||||
"search_term": { "type": "string" },
|
||||
"limit": { "type": "integer" }
|
||||
},
|
||||
"type": "struct"
|
||||
}
|
||||
},
|
||||
"guard": "TELODENDRIA_SCHEMA_USERDIRECTORYREQUEST_H"
|
||||
}
|
|
@ -71,6 +71,7 @@ RouterBuild(void)
|
|||
|
||||
R("/_matrix/client/v3/profile/(.*)", RouteUserProfile);
|
||||
R("/_matrix/client/v3/profile/(.*)/(avatar_url|displayname)", RouteUserProfile);
|
||||
R("/_matrix/client/v3/user_directory/search", RouteUserDirectory);
|
||||
|
||||
R("/_matrix/client/v3/user/(.*)/filter", RouteFilter);
|
||||
R("/_matrix/client/v3/user/(.*)/filter/(.*)", RouteFilter);
|
||||
|
|
199
src/Routes/RouteUserDirectory.c
Normal file
199
src/Routes/RouteUserDirectory.c
Normal file
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without dirRequest.limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <Routes.h>
|
||||
|
||||
#include <Cytoplasm/Array.h>
|
||||
#include <Cytoplasm/HashMap.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Db.h>
|
||||
|
||||
#include <Schema/UserDirectoryRequest.h>
|
||||
|
||||
#include <User.h>
|
||||
|
||||
ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||
{
|
||||
RouteArgs *args = argp;
|
||||
HashMap *response = NULL;
|
||||
HashMap *request = NULL;
|
||||
|
||||
Array *users = NULL;
|
||||
Array *results = NULL;
|
||||
|
||||
Db *db = args->matrixArgs->db;
|
||||
|
||||
Config *config = NULL;
|
||||
|
||||
User *user = NULL;
|
||||
|
||||
char *token = NULL;
|
||||
char *requesterName = NULL;
|
||||
char *msg = NULL;
|
||||
|
||||
UserDirectoryRequest dirRequest;
|
||||
|
||||
size_t i, included;
|
||||
|
||||
(void) path;
|
||||
|
||||
dirRequest.search_term = NULL;
|
||||
dirRequest.limit = Int64Create(0, 10);
|
||||
|
||||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
msg = "Request supports only POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
if (!UserDirectoryRequestFromJson(request, &dirRequest, &msg))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
goto finish;
|
||||
}
|
||||
if (!dirRequest.search_term)
|
||||
{
|
||||
msg = "Field 'search_term' not set.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
goto finish;
|
||||
|
||||
}
|
||||
|
||||
response = MatrixGetAccessToken(args->context, &token);
|
||||
if (response)
|
||||
{
|
||||
return response;
|
||||
}
|
||||
|
||||
/* TODO: Actually use information related to the user. */
|
||||
user = UserAuthenticate(db, token);
|
||||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
requesterName = UserGetName(user);
|
||||
|
||||
response = HashMapCreate();
|
||||
results = ArrayCreate();
|
||||
|
||||
/* TODO: Check for users matching search term and users outside our
|
||||
* local server. */
|
||||
users = DbList(db, 1, "users");
|
||||
|
||||
|
||||
/* Offending line? */
|
||||
config = ConfigLock(db);
|
||||
if (!config)
|
||||
{
|
||||
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
|
||||
goto finish;
|
||||
}
|
||||
|
||||
#define IncludedLtLimit (Int64Lt(Int64Create(0, included), dirRequest.limit))
|
||||
for (i = 0, included = 0; i < ArraySize(users) && IncludedLtLimit; i++)
|
||||
#undef IncludedLtLimit
|
||||
{
|
||||
HashMap *obj;
|
||||
User *currentUser;
|
||||
char *name = ArrayGet(users, i);
|
||||
char *displayName;
|
||||
char *lowerDisplayName;
|
||||
char *avatarUrl;
|
||||
|
||||
if (!StrEquals(name, requesterName))
|
||||
{
|
||||
currentUser = UserLock(db, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentUser = user;
|
||||
}
|
||||
|
||||
displayName = UserGetProfile(currentUser, "displayname");
|
||||
lowerDisplayName = StrLower(displayName);
|
||||
avatarUrl = UserGetProfile(currentUser, "avatar_url");
|
||||
|
||||
/* Check for the user ID and display name. */
|
||||
if (strstr(name, dirRequest.search_term) ||
|
||||
(lowerDisplayName &&
|
||||
strstr(lowerDisplayName, dirRequest.search_term)))
|
||||
{
|
||||
included++;
|
||||
|
||||
obj = HashMapCreate();
|
||||
if (displayName)
|
||||
{
|
||||
JsonSet(obj, JsonValueString(displayName), 1, "display_name");
|
||||
}
|
||||
if (avatarUrl)
|
||||
{
|
||||
JsonSet(obj, JsonValueString(displayName), 1, "avatar_url");
|
||||
}
|
||||
if (name)
|
||||
{
|
||||
char *uID = StrConcat(4, "@", name, ":", config->serverName);
|
||||
JsonSet(obj, JsonValueString(uID), 1, "user_id");
|
||||
Free(uID);
|
||||
}
|
||||
ArrayAdd(results, JsonValueObject(obj));
|
||||
}
|
||||
if (lowerDisplayName)
|
||||
{
|
||||
Free(lowerDisplayName);
|
||||
}
|
||||
if (!StrEquals(name, requesterName))
|
||||
{
|
||||
UserUnlock(currentUser);
|
||||
}
|
||||
}
|
||||
JsonSet(response, JsonValueArray(results), 1, "results");
|
||||
JsonSet(response, JsonValueBoolean(Int64Eq(included, dirRequest.limit)),
|
||||
1, "limited");
|
||||
|
||||
finish:
|
||||
UserUnlock(user);
|
||||
JsonFree(request);
|
||||
DbListFree(users);
|
||||
ConfigUnlock(config);
|
||||
UserDirectoryRequestFree(&dirRequest);
|
||||
return response;
|
||||
}
|
|
@ -85,6 +85,7 @@ ROUTE(RouteChangePwd);
|
|||
ROUTE(RouteDeactivate);
|
||||
ROUTE(RouteTokenValid);
|
||||
ROUTE(RouteUserProfile);
|
||||
ROUTE(RouteUserDirectory);
|
||||
ROUTE(RouteRequestToken);
|
||||
|
||||
ROUTE(RouteUiaFallback);
|
||||
|
|
61
tools/bin/tt
61
tools/bin/tt
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
BASE="http://localhost:8008"
|
||||
USERNAME="tt_user"
|
||||
PASSWORD=$(json -e 'p@s$w0rd')
|
||||
|
||||
ENDPOINT="$1"
|
||||
|
||||
: "${METH:=GET}"
|
||||
|
||||
register_payload() {
|
||||
printf '{'
|
||||
printf ' "auth": {'
|
||||
printf ' "type": "m.login.dummy",'
|
||||
printf ' "session": %s' "$(json -e "$1")"
|
||||
printf ' },'
|
||||
printf ' "username": %s,' "$(json -e "$USERNAME")"
|
||||
printf ' "password": %s,' "$PASSWORD"
|
||||
printf ' "inhibit_login": true '
|
||||
printf '}'
|
||||
}
|
||||
|
||||
login_payload() {
|
||||
printf '{'
|
||||
printf ' "identifier": {'
|
||||
printf ' "type": "m.id.user",'
|
||||
printf ' "user": %s' "$(json -e "$USERNAME")"
|
||||
printf ' },'
|
||||
printf ' "type": "m.login.password",'
|
||||
printf ' "password": %s' "$PASSWORD"
|
||||
printf '}'
|
||||
}
|
||||
|
||||
# Check if user is available. If it is, register it.
|
||||
user_available=$(http "$BASE/_matrix/client/v3/register/available?username=$USERNAME" | json -s "available")
|
||||
if [ "$user_available" = "true" ]; then
|
||||
session=$(http -X POST -d '{}' "$BASE/_matrix/client/v3/register" | json -s "session->@decode")
|
||||
register_payload "$session" | http -X POST -d @- "$BASE/_matrix/client/v3/register" > /dev/null
|
||||
fi
|
||||
|
||||
# Log in
|
||||
RESPONSE=$(login_payload | http -X POST -d @- "$BASE/_matrix/client/v3/login")
|
||||
|
||||
ACCESS_TOKEN=$(echo "$RESPONSE" | json -s "access_token->@decode")
|
||||
|
||||
if [ -z "$ACCESS_TOKEN" ]; then
|
||||
echo "Failed to log in."
|
||||
echo "$RESPONSE" | json
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make request
|
||||
if [ -n "$DATA" ]; then
|
||||
http -X "$METH" -d "$DATA" -H "Authorization: Bearer $ACCESS_TOKEN" "${BASE}${ENDPOINT}" | json
|
||||
else
|
||||
http -X "$METH" -H "Authorization: Bearer $ACCESS_TOKEN" "${BASE}${ENDPOINT}" | json
|
||||
fi
|
||||
|
||||
# Log out
|
||||
http -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
"$BASE/_matrix/client/v3/logout/all" > /dev/null
|
Loading…
Reference in a new issue