[ADD/WIP] Add some HTTP request code

We can now *register* users!
This commit is contained in:
LDA 2024-06-13 09:35:57 +02:00
commit 0fa95c2d14
12 changed files with 320 additions and 11 deletions

View file

@ -4,6 +4,7 @@
#include <string.h>
#include <Parsee.h>
#include <AS.h>
int
Main(void)
@ -12,12 +13,36 @@ Main(void)
HttpServerConfig conf;
ParseeData *data;
const ParseeConfig *parseeConf;
Stream *yaml;
Log(LOG_INFO, "%s - v%s", NAME, VERSION);
ParseeConfigLoad("parsee.json");
ParseeConfigInit();
ParseeExportConfigYAML(StreamStdout());
yaml = StreamOpen("parsee.yaml", "w");
ParseeExportConfigYAML(yaml);
StreamClose(yaml);
parseeConf = ParseeConfigGet();
Log(LOG_INFO, "HS token: %s", parseeConf->hs_token);
{
/* Create user. We don't actually care about the value as we can
* masquerade, as long as it exists. */
HttpClientContext *ctx = ParseeCreateRequest(
parseeConf,
HTTP_POST, "/_matrix/client/v3/register"
);
HashMap *json = HashMapCreate();
HashMapSet(json,"type",JsonValueString("m.login.application_service"));
HashMapSet(json,"username",JsonValueString(parseeConf->sender_localpart));
ASAuthenticateRequest(parseeConf, ctx);
Log(LOG_INFO, "Got %d", ParseeSetRequestJSON(ctx, json));
HttpClientContextFree(ctx);
JsonFree(json);
}
memset(&conf, 0, sizeof(conf));
conf.port = parseeConf->port;