mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 22:55:11 +00:00
[ADD/WIP] Start making a simple SAX parser, ASwerk
This commit is contained in:
parent
0fa95c2d14
commit
79217d3608
14 changed files with 1066 additions and 26 deletions
130
src/AS.c
130
src/AS.c
|
|
@ -54,3 +54,133 @@ ASAuthenticateRequest(ParseeConfig *data, HttpClientContext *ctx)
|
|||
HttpRequestHeader(ctx, "Authorization", bearer);
|
||||
Free(bearer);
|
||||
}
|
||||
bool
|
||||
ASRegisterUser(ParseeConfig *conf, char *user)
|
||||
{
|
||||
HttpClientContext *ctx = NULL;
|
||||
HashMap *json = NULL;
|
||||
HttpStatus status;
|
||||
if (!conf || !user)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Create user. We don't actually care about the value as we can
|
||||
* masquerade, as long as it exists. */
|
||||
ctx = ParseeCreateRequest(
|
||||
conf,
|
||||
HTTP_POST, "/_matrix/client/v3/register"
|
||||
);
|
||||
json = HashMapCreate();
|
||||
|
||||
HashMapSet(json,"type",JsonValueString("m.login.application_service"));
|
||||
HashMapSet(json,"username",JsonValueString(user));
|
||||
|
||||
ASAuthenticateRequest(conf, ctx);
|
||||
status = ParseeSetRequestJSON(ctx, json);
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(json);
|
||||
|
||||
return status == HTTP_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ASPing(ParseeConfig *conf)
|
||||
{
|
||||
HttpClientContext *ctx = NULL;
|
||||
HashMap *json = NULL;
|
||||
char *path;
|
||||
if (!conf)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log(LOG_NOTICE, "Pinging...");
|
||||
path = StrConcat(3,
|
||||
"/_matrix/client/v1/appservice/",
|
||||
"Parsee%20XMPP",
|
||||
"/ping"
|
||||
);
|
||||
ctx = ParseeCreateRequest(
|
||||
conf,
|
||||
HTTP_POST, path
|
||||
);
|
||||
Free(path);
|
||||
json = HashMapCreate();
|
||||
ASAuthenticateRequest(conf, ctx);
|
||||
ParseeSetRequestJSON(ctx, json);
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(json);
|
||||
}
|
||||
void
|
||||
ASJoin(ParseeConfig *conf, char *id, char *masquerade)
|
||||
{
|
||||
HttpClientContext *ctx = NULL;
|
||||
HashMap *json = NULL, *params_obj;
|
||||
char *path, *params;
|
||||
if (!conf || !id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
params_obj = HashMapCreate();
|
||||
if (masquerade)
|
||||
{
|
||||
HashMapSet(params_obj, "user_id", masquerade);
|
||||
}
|
||||
params = HttpParamEncode(params_obj);
|
||||
HashMapFree(params_obj);
|
||||
path = StrConcat(4,
|
||||
"/_matrix/client/v3/rooms/", id, "/join?",
|
||||
params
|
||||
);
|
||||
Free(params);
|
||||
|
||||
ctx = ParseeCreateRequest(
|
||||
conf,
|
||||
HTTP_POST, path
|
||||
);
|
||||
Free(path);
|
||||
json = HashMapCreate();
|
||||
ASAuthenticateRequest(conf, ctx);
|
||||
ParseeSetRequestJSON(ctx, json);
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(json);
|
||||
}
|
||||
void
|
||||
ASSend(ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
|
||||
{
|
||||
HttpClientContext *ctx = NULL;
|
||||
HashMap *json = NULL, *params_obj;
|
||||
char *path, *params;
|
||||
char *txn;
|
||||
if (!conf || !id || !type || !c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
txn = StrRandom(16);
|
||||
params_obj = HashMapCreate();
|
||||
if (user)
|
||||
{
|
||||
HashMapSet(params_obj, "user_id", user);
|
||||
}
|
||||
params = HttpParamEncode(params_obj);
|
||||
HashMapFree(params_obj);
|
||||
path = StrConcat(8,
|
||||
"/_matrix/client/v3/rooms/",
|
||||
id, "/send/", type, "/", txn, "?",
|
||||
params
|
||||
);
|
||||
Log(LOG_INFO, "Sending %s", path);
|
||||
Free(params);
|
||||
Free(txn);
|
||||
|
||||
ctx = ParseeCreateRequest(conf, HTTP_PUT, path);
|
||||
Free(path);
|
||||
json = HashMapCreate();
|
||||
ASAuthenticateRequest(conf, ctx);
|
||||
Log(LOG_INFO, "%d", ParseeSetRequestJSON(ctx, c));
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(c);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue