mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +00:00
[ADD/WIP] Add some HTTP request code
We can now *register* users!
This commit is contained in:
parent
47c98cbbe3
commit
0fa95c2d14
12 changed files with 320 additions and 11 deletions
18
src/include/AS.h
Normal file
18
src/include/AS.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PARSEE_AS_H
|
||||
#define PARSEE_AS_H
|
||||
|
||||
#include <Cytoplasm/HttpClient.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
|
||||
#include <Parsee.h>
|
||||
#include <Routes.h>
|
||||
|
||||
/* Verifies a request from the homeserver to match the
|
||||
* hs_token. */
|
||||
extern HashMap * ASVerifyRequest(ParseeHttpArg *);
|
||||
|
||||
/* Authenticates a request with the correct as_token.
|
||||
* It does not send the request, however. */
|
||||
extern void ASAuthenticateRequest(ParseeConfig *, HttpClientContext *);
|
||||
|
||||
#endif
|
||||
8
src/include/Matrix.h
Normal file
8
src/include/Matrix.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef PARSEE_MATRIX_H
|
||||
#define PARSEE_MATRIX_H
|
||||
|
||||
#include <Cytoplasm/Json.h>
|
||||
|
||||
/* Creates an error message JSON, with the specified code and message. */
|
||||
extern HashMap * MatrixCreateError(char *err, char *msg);
|
||||
#endif
|
||||
|
|
@ -3,16 +3,21 @@
|
|||
|
||||
#include <Cytoplasm/HttpServer.h>
|
||||
#include <Cytoplasm/HttpRouter.h>
|
||||
#include <Cytoplasm/HttpClient.h>
|
||||
#include <Cytoplasm/Stream.h>
|
||||
|
||||
typedef struct ParseeConfig {
|
||||
char *as_token, *hs_token;
|
||||
char *as_token, *hs_token;
|
||||
/* id here is "Parsee XMPP". */
|
||||
char *sender_localpart;
|
||||
char *namespace_base;
|
||||
char *sender_localpart;
|
||||
char *namespace_base;
|
||||
|
||||
char *listen_as;
|
||||
int port;
|
||||
char *listen_as;
|
||||
int port;
|
||||
|
||||
/* Homeserver port info */
|
||||
char *homeserver_host;
|
||||
int homeserver_port;
|
||||
} ParseeConfig;
|
||||
|
||||
typedef struct ParseeData {
|
||||
|
|
@ -42,4 +47,9 @@ extern void ParseeFreeData(ParseeData *);
|
|||
|
||||
/* HTTP server handler for Parsee, takes in a config. */
|
||||
extern void ParseeRequest(HttpServerContext *, void *);
|
||||
|
||||
extern HttpClientContext * ParseeCreateRequest(ParseeConfig *, HttpRequestMethod, char *);
|
||||
|
||||
/* Sends headers, and writes the JSON object. */
|
||||
extern HttpStatus ParseeSetRequestJSON(HttpClientContext *, HashMap *);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,12 +9,29 @@ typedef struct ParseeHttpArg {
|
|||
} ParseeHttpArg;
|
||||
|
||||
/* A list of all routes. */
|
||||
#define ROUTES X_ROUTE("/", RouteRoot)
|
||||
#define ROUTES X_ROUTE("/", RouteRoot) \
|
||||
X_ROUTE("/_matrix/app/v1/transactions/(.*)", RouteTxns)
|
||||
|
||||
#define X_ROUTE(path, name) extern void * name(Array *, void *);
|
||||
ROUTES
|
||||
#undef X_ROUTE
|
||||
|
||||
#define RouteHead(name, pathargs, argp) void * \
|
||||
name(Array * pathargs, void *argp)
|
||||
#define RouteHead(name, pathargs, argp) void * \
|
||||
name(Array * pathargs, void *argp)
|
||||
#define RequestJSON() do \
|
||||
{ \
|
||||
Stream *s = args->stream;\
|
||||
if (!(request = JsonDecode(s))) \
|
||||
{ \
|
||||
HttpResponseStatus( \
|
||||
args->ctx, \
|
||||
HTTP_BAD_REQUEST \
|
||||
); \
|
||||
response = MatrixCreateError(\
|
||||
"M_NO_JSON", \
|
||||
"Invalid JSON stream." \
|
||||
); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue