Format source code.

This commit is contained in:
Jordan Bancino 2023-03-16 12:29:38 +00:00
parent 7d9770fc12
commit 6ee1857f5f
10 changed files with 190 additions and 53 deletions

View file

@ -1,3 +1,26 @@
/*
* 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 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 <Io.h> #include <Io.h>
#include <Memory.h> #include <Memory.h>
@ -41,7 +64,7 @@ IoCreate(void *cookie, IoFunctions funcs)
} }
ssize_t ssize_t
IoRead(Io *io, void *buf, size_t nBytes) IoRead(Io * io, void *buf, size_t nBytes)
{ {
if (!io || !io->io.read) if (!io || !io->io.read)
{ {
@ -53,7 +76,7 @@ IoRead(Io *io, void *buf, size_t nBytes)
} }
ssize_t ssize_t
IoWrite(Io *io, void *buf, size_t nBytes) IoWrite(Io * io, void *buf, size_t nBytes)
{ {
if (!io || !io->io.write) if (!io || !io->io.write)
{ {
@ -65,7 +88,7 @@ IoWrite(Io *io, void *buf, size_t nBytes)
} }
off_t off_t
IoSeek(Io *io, off_t offset, int whence) IoSeek(Io * io, off_t offset, int whence)
{ {
if (!io) if (!io)
{ {
@ -83,7 +106,7 @@ IoSeek(Io *io, off_t offset, int whence)
} }
int int
IoClose(Io *io) IoClose(Io * io)
{ {
int ret; int ret;
@ -108,7 +131,7 @@ IoClose(Io *io)
} }
int int
IoVprintf(Io *io, const char *fmt, va_list ap) IoVprintf(Io * io, const char *fmt, va_list ap)
{ {
char *buf; char *buf;
size_t write; size_t write;
@ -134,13 +157,13 @@ IoVprintf(Io *io, const char *fmt, va_list ap)
return write; return write;
} }
/* Number of bytes to write exceeded buffer size; this should /* Number of bytes to write exceeded buffer size; this should be
* be rare, but may occasionally happen. If it does, realloc to * rare, but may occasionally happen. If it does, realloc to the
* the correct size and try again. * correct size and try again. */
*/
if (write >= IO_BUFFER) if (write >= IO_BUFFER)
{ {
char *new = Realloc(buf, write + 1); char *new = Realloc(buf, write + 1);
if (!new) if (!new)
{ {
Free(buf); Free(buf);
@ -160,7 +183,7 @@ IoVprintf(Io *io, const char *fmt, va_list ap)
} }
int int
IoPrintf(Io *io, const char *fmt, ...) IoPrintf(Io * io, const char *fmt,...)
{ {
va_list ap; va_list ap;
int ret; int ret;
@ -173,7 +196,7 @@ IoPrintf(Io *io, const char *fmt, ...)
} }
ssize_t ssize_t
IoCopy(Io *in, Io *out) IoCopy(Io * in, Io * out)
{ {
ssize_t nBytes = 0; ssize_t nBytes = 0;
char buf[IO_BUFFER]; char buf[IO_BUFFER];

View file

@ -1,3 +1,26 @@
/*
* 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 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 <Io.h> #include <Io.h>
#include <Memory.h> #include <Memory.h>

View file

@ -1,3 +1,26 @@
/*
* 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 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 <Io.h> #include <Io.h>
#include <stdio.h> #include <stdio.h>
@ -35,7 +58,7 @@ IoCloseFile(void *cookie)
} }
Io * Io *
IoFile(FILE *fp) IoFile(FILE * fp)
{ {
IoFunctions f; IoFunctions f;
@ -51,4 +74,3 @@ IoFile(FILE *fp)
return IoCreate(fp, f); return IoCreate(fp, f);
} }

View file

@ -745,10 +745,9 @@ JsonConsumeWhitespace(JsonParserState * state)
} }
} }
/* As soon as we've successfully read a byte, treat /* As soon as we've successfully read a byte, treat future
* future EAGAINs as EOF, because some clients don't * EAGAINs as EOF, because some clients don't properly shutdown
* properly shutdown their sockets. * their sockets. */
*/
readFlg = 1; readFlg = 1;
tries = 0; tries = 0;

View file

@ -50,7 +50,7 @@ RegTokenValid(RegTokenInfo * token)
expiration = JsonValueAsInteger(HashMapGet(tokenJson, "expires_on")); expiration = JsonValueAsInteger(HashMapGet(tokenJson, "expires_on"));
return (!expiration || (UtilServerTs() <= expiration)) && return (!expiration || (UtilServerTs() <= expiration)) &&
(uses == -1 || used < uses); (uses == -1 || used < uses);
} }
void void
RegTokenUse(RegTokenInfo * token) RegTokenUse(RegTokenInfo * token)
@ -204,9 +204,9 @@ RegTokenCreate(Db * db, char *name, char *owner, unsigned long expires, int uses
return NULL; return NULL;
} }
/* -1 indicates infinite uses; zero and all positive values are a valid /* -1 indicates infinite uses; zero and all positive values are a
* number of uses; althought zero would be rather useless. Anything less * valid number of uses; althought zero would be rather useless.
* than -1 doesn't make sense. */ * Anything less than -1 doesn't make sense. */
if (uses < -1) if (uses < -1)
{ {
return NULL; return NULL;

View file

@ -1,3 +1,26 @@
/*
* 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 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 <Stream.h> #include <Stream.h>
#include <Io.h> #include <Io.h>

View file

@ -429,7 +429,7 @@ UserDeactivate(User * user)
} }
int int
UserDeactivated(User *user) UserDeactivated(User * user)
{ {
HashMap *json; HashMap *json;

View file

@ -1,3 +1,26 @@
/*
* 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 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.
*/
#ifndef TELODENDRIA_IO_H #ifndef TELODENDRIA_IO_H
#define TELODENDRIA_IO_H #define TELODENDRIA_IO_H
@ -11,9 +34,9 @@
typedef struct Io Io; typedef struct Io Io;
typedef ssize_t (IoReadFunc) (void *, void *, size_t); typedef ssize_t(IoReadFunc) (void *, void *, size_t);
typedef ssize_t (IoWriteFunc) (void *, void *, size_t); typedef ssize_t(IoWriteFunc) (void *, void *, size_t);
typedef off_t (IoSeekFunc) (void *, off_t, int); typedef off_t(IoSeekFunc) (void *, off_t, int);
typedef int (IoCloseFunc) (void *); typedef int (IoCloseFunc) (void *);
typedef struct IoFunctions typedef struct IoFunctions
@ -25,36 +48,36 @@ typedef struct IoFunctions
} IoFunctions; } IoFunctions;
extern Io * extern Io *
IoCreate(void *, IoFunctions); IoCreate(void *, IoFunctions);
extern ssize_t extern ssize_t
IoRead(Io *, void *, size_t); IoRead(Io *, void *, size_t);
extern ssize_t extern ssize_t
IoWrite(Io *, void *, size_t); IoWrite(Io *, void *, size_t);
extern off_t extern off_t
IoSeek(Io *, off_t, int); IoSeek(Io *, off_t, int);
extern int extern int
IoClose(Io *); IoClose(Io *);
extern int extern int
IoVprintf(Io *, const char *, va_list); IoVprintf(Io *, const char *, va_list);
extern int extern int
IoPrintf(Io *, const char *, ...); IoPrintf(Io *, const char *,...);
extern ssize_t extern ssize_t
IoCopy(Io *, Io *); IoCopy(Io *, Io *);
extern Io * extern Io *
IoFd(int); IoFd(int);
extern Io * extern Io *
IoOpen(const char *, int, mode_t); IoOpen(const char *, int, mode_t);
extern Io * extern Io *
IoFile(FILE *); IoFile(FILE *);
#endif /* TELODENDRIA_IO_H */ #endif /* TELODENDRIA_IO_H */

View file

@ -67,7 +67,8 @@ ROUTE(RouteRegister); /* /_matrix/client/(r0|v3)/register */
ROUTE(RouteRefresh); /* /_matrix/client/(r0|v3)/refresh */ ROUTE(RouteRefresh); /* /_matrix/client/(r0|v3)/refresh */
ROUTE(RouteWhoami); /* /_matrix/client/(r0|v3)/whoami */ ROUTE(RouteWhoami); /* /_matrix/client/(r0|v3)/whoami */
ROUTE(RouteTokenValid); /* /_matrix/client/v1/register/m.login.registration_token/validity */ ROUTE(RouteTokenValid); /* /_matrix/client/v1/register/m.logi
* n.registration_token/validity */
#undef ROUTE #undef ROUTE

View file

@ -1,3 +1,26 @@
/*
* 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 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.
*/
#ifndef TELODENDRIA_STREAM_H #ifndef TELODENDRIA_STREAM_H
#define TELODENDRIA_STREAM_H #define TELODENDRIA_STREAM_H
@ -8,45 +31,45 @@
typedef struct Stream Stream; typedef struct Stream Stream;
extern Stream * extern Stream *
StreamIo(Io *io); StreamIo(Io * io);
extern Stream * extern Stream *
StreamFd(int); StreamFd(int);
extern Stream * extern Stream *
StreamOpen(const char *, const char *); StreamOpen(const char *, const char *);
extern int extern int
StreamClose(Stream *); StreamClose(Stream *);
extern int extern int
StreamVprintf(Stream *, const char *, va_list); StreamVprintf(Stream *, const char *, va_list);
extern int extern int
StreamPrintf(Stream *, const char *, ...); StreamPrintf(Stream *, const char *,...);
extern int extern int
StreamGetc(Stream *); StreamGetc(Stream *);
extern int extern int
StreamUngetc(Stream *, int); StreamUngetc(Stream *, int);
extern int extern int
StreamPutc(Stream *, int); StreamPutc(Stream *, int);
extern int extern int
StreamEof(Stream *); StreamEof(Stream *);
extern int extern int
StreamError(Stream *); StreamError(Stream *);
extern void extern void
StreamClearError(Stream *); StreamClearError(Stream *);
extern int extern int
StreamFlush(Stream *); StreamFlush(Stream *);
extern ssize_t extern ssize_t
StreamCopy(Stream *, Stream *); StreamCopy(Stream *, Stream *);
#endif /* TELODENDRIA_STREAM_H */ #endif /* TELODENDRIA_STREAM_H */