[MOD] Read the config file for tool DB access

This commit is contained in:
LDA 2024-09-08 16:12:27 +02:00
commit 9775bd8d4e
6 changed files with 157 additions and 115 deletions

View file

@ -10,73 +10,7 @@
* Under CC0, as its a rather useful example of a Parsee tool.
* See LICENSE for more information about Parsee's licensing. */
#include <Cytoplasm/HttpClient.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Json.h>
#include <Cytoplasm/Args.h>
#include <Cytoplasm/Util.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Uri.h>
#include <Cytoplasm/Str.h>
#include <Cytoplasm/Db.h>
#include <stdlib.h>
static Uri *
DelegateServer(char *raw)
{
HttpClientContext *ctx = NULL;
Stream *stream = NULL;
HashMap *reply = NULL;
Uri *ret = NULL;
if (!raw)
{
return NULL;
}
ctx = HttpRequest(
HTTP_GET,
HTTP_FLAG_TLS, 443,
raw, "/.well-known/matrix/client"
);
HttpRequestSendHeaders(ctx);
switch (HttpRequestSend(ctx))
{
case HTTP_OK:
stream = HttpClientStream(ctx);
reply = JsonDecode(stream);
if (!reply)
{
goto end;
}
ret = UriParse(JsonValueAsString(JsonGet(
reply, 2,
"m.homeserver", "base_url"
)));
break;
default:
/* TODO */
break;
}
if (ret && !ret->port && StrEquals(ret->proto, "https"))
{
ret->port = 443;
}
if (ret && !ret->port)
{
ret->port = 80;
}
end:
HttpClientContextFree(ctx);
JsonFree(reply);
return ret;
}
#include "common.h"
int
Main(Array *args, HashMap *env)