From 6ee1857f5f9390bff67eb2824099e43494e93b44 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Thu, 16 Mar 2023 12:29:38 +0000 Subject: [PATCH] Format source code. --- src/Io.c | 45 ++++++++++++++++++++++++++++--------- src/Io/IoFd.c | 23 +++++++++++++++++++ src/Io/IoFile.c | 26 ++++++++++++++++++++-- src/Json.c | 7 +++--- src/RegToken.c | 8 +++---- src/Stream.c | 23 +++++++++++++++++++ src/User.c | 2 +- src/include/Io.h | 53 +++++++++++++++++++++++++++++++------------- src/include/Routes.h | 3 ++- src/include/Stream.h | 53 +++++++++++++++++++++++++++++++------------- 10 files changed, 190 insertions(+), 53 deletions(-) diff --git a/src/Io.c b/src/Io.c index 37c3e6a..16fc846 100644 --- a/src/Io.c +++ b/src/Io.c @@ -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 #include @@ -41,7 +64,7 @@ IoCreate(void *cookie, IoFunctions funcs) } ssize_t -IoRead(Io *io, void *buf, size_t nBytes) +IoRead(Io * io, void *buf, size_t nBytes) { if (!io || !io->io.read) { @@ -53,7 +76,7 @@ IoRead(Io *io, void *buf, size_t nBytes) } ssize_t -IoWrite(Io *io, void *buf, size_t nBytes) +IoWrite(Io * io, void *buf, size_t nBytes) { if (!io || !io->io.write) { @@ -65,7 +88,7 @@ IoWrite(Io *io, void *buf, size_t nBytes) } off_t -IoSeek(Io *io, off_t offset, int whence) +IoSeek(Io * io, off_t offset, int whence) { if (!io) { @@ -83,7 +106,7 @@ IoSeek(Io *io, off_t offset, int whence) } int -IoClose(Io *io) +IoClose(Io * io) { int ret; @@ -108,7 +131,7 @@ IoClose(Io *io) } int -IoVprintf(Io *io, const char *fmt, va_list ap) +IoVprintf(Io * io, const char *fmt, va_list ap) { char *buf; size_t write; @@ -134,13 +157,13 @@ IoVprintf(Io *io, const char *fmt, va_list ap) return write; } - /* Number of bytes to write exceeded buffer size; this should - * be rare, but may occasionally happen. If it does, realloc to - * the correct size and try again. - */ + /* Number of bytes to write exceeded buffer size; this should be + * rare, but may occasionally happen. If it does, realloc to the + * correct size and try again. */ if (write >= IO_BUFFER) { char *new = Realloc(buf, write + 1); + if (!new) { Free(buf); @@ -160,7 +183,7 @@ IoVprintf(Io *io, const char *fmt, va_list ap) } int -IoPrintf(Io *io, const char *fmt, ...) +IoPrintf(Io * io, const char *fmt,...) { va_list ap; int ret; @@ -173,7 +196,7 @@ IoPrintf(Io *io, const char *fmt, ...) } ssize_t -IoCopy(Io *in, Io *out) +IoCopy(Io * in, Io * out) { ssize_t nBytes = 0; char buf[IO_BUFFER]; diff --git a/src/Io/IoFd.c b/src/Io/IoFd.c index e381587..eaa1539 100644 --- a/src/Io/IoFd.c +++ b/src/Io/IoFd.c @@ -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 #include diff --git a/src/Io/IoFile.c b/src/Io/IoFile.c index 63d7dde..fe44291 100644 --- a/src/Io/IoFile.c +++ b/src/Io/IoFile.c @@ -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 #include @@ -35,7 +58,7 @@ IoCloseFile(void *cookie) } Io * -IoFile(FILE *fp) +IoFile(FILE * fp) { IoFunctions f; @@ -51,4 +74,3 @@ IoFile(FILE *fp) return IoCreate(fp, f); } - diff --git a/src/Json.c b/src/Json.c index 50ac50d..90c6c3d 100644 --- a/src/Json.c +++ b/src/Json.c @@ -745,10 +745,9 @@ JsonConsumeWhitespace(JsonParserState * state) } } - /* As soon as we've successfully read a byte, treat - * future EAGAINs as EOF, because some clients don't - * properly shutdown their sockets. - */ + /* As soon as we've successfully read a byte, treat future + * EAGAINs as EOF, because some clients don't properly shutdown + * their sockets. */ readFlg = 1; tries = 0; diff --git a/src/RegToken.c b/src/RegToken.c index 0e95d21..f132c46 100644 --- a/src/RegToken.c +++ b/src/RegToken.c @@ -50,7 +50,7 @@ RegTokenValid(RegTokenInfo * token) expiration = JsonValueAsInteger(HashMapGet(tokenJson, "expires_on")); return (!expiration || (UtilServerTs() <= expiration)) && - (uses == -1 || used < uses); + (uses == -1 || used < uses); } void RegTokenUse(RegTokenInfo * token) @@ -204,9 +204,9 @@ RegTokenCreate(Db * db, char *name, char *owner, unsigned long expires, int uses return NULL; } - /* -1 indicates infinite uses; zero and all positive values are a valid - * number of uses; althought zero would be rather useless. Anything less - * than -1 doesn't make sense. */ + /* -1 indicates infinite uses; zero and all positive values are a + * valid number of uses; althought zero would be rather useless. + * Anything less than -1 doesn't make sense. */ if (uses < -1) { return NULL; diff --git a/src/Stream.c b/src/Stream.c index 6a405df..ee34fab 100644 --- a/src/Stream.c +++ b/src/Stream.c @@ -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 #include diff --git a/src/User.c b/src/User.c index 2ec453d..2df884b 100644 --- a/src/User.c +++ b/src/User.c @@ -429,7 +429,7 @@ UserDeactivate(User * user) } int -UserDeactivated(User *user) +UserDeactivated(User * user) { HashMap *json; diff --git a/src/include/Io.h b/src/include/Io.h index 87c6d6a..af52903 100644 --- a/src/include/Io.h +++ b/src/include/Io.h @@ -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 #define TELODENDRIA_IO_H @@ -11,9 +34,9 @@ typedef struct Io Io; -typedef ssize_t (IoReadFunc) (void *, void *, size_t); -typedef ssize_t (IoWriteFunc) (void *, void *, size_t); -typedef off_t (IoSeekFunc) (void *, off_t, int); +typedef ssize_t(IoReadFunc) (void *, void *, size_t); +typedef ssize_t(IoWriteFunc) (void *, void *, size_t); +typedef off_t(IoSeekFunc) (void *, off_t, int); typedef int (IoCloseFunc) (void *); typedef struct IoFunctions @@ -25,36 +48,36 @@ typedef struct IoFunctions } IoFunctions; extern Io * -IoCreate(void *, IoFunctions); + IoCreate(void *, IoFunctions); extern ssize_t -IoRead(Io *, void *, size_t); + IoRead(Io *, void *, size_t); extern ssize_t -IoWrite(Io *, void *, size_t); + IoWrite(Io *, void *, size_t); extern off_t -IoSeek(Io *, off_t, int); + IoSeek(Io *, off_t, int); extern int -IoClose(Io *); + IoClose(Io *); extern int -IoVprintf(Io *, const char *, va_list); + IoVprintf(Io *, const char *, va_list); extern int -IoPrintf(Io *, const char *, ...); + IoPrintf(Io *, const char *,...); extern ssize_t -IoCopy(Io *, Io *); + IoCopy(Io *, Io *); extern Io * -IoFd(int); + IoFd(int); extern Io * -IoOpen(const char *, int, mode_t); + IoOpen(const char *, int, mode_t); extern Io * -IoFile(FILE *); + IoFile(FILE *); -#endif /* TELODENDRIA_IO_H */ +#endif /* TELODENDRIA_IO_H */ diff --git a/src/include/Routes.h b/src/include/Routes.h index eb4791a..4156a93 100644 --- a/src/include/Routes.h +++ b/src/include/Routes.h @@ -67,7 +67,8 @@ ROUTE(RouteRegister); /* /_matrix/client/(r0|v3)/register */ ROUTE(RouteRefresh); /* /_matrix/client/(r0|v3)/refresh */ 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 diff --git a/src/include/Stream.h b/src/include/Stream.h index 0c37d23..2c9698b 100644 --- a/src/include/Stream.h +++ b/src/include/Stream.h @@ -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 #define TELODENDRIA_STREAM_H @@ -8,45 +31,45 @@ typedef struct Stream Stream; extern Stream * -StreamIo(Io *io); + StreamIo(Io * io); extern Stream * -StreamFd(int); + StreamFd(int); extern Stream * -StreamOpen(const char *, const char *); + StreamOpen(const char *, const char *); extern int -StreamClose(Stream *); + StreamClose(Stream *); extern int -StreamVprintf(Stream *, const char *, va_list); + StreamVprintf(Stream *, const char *, va_list); extern int -StreamPrintf(Stream *, const char *, ...); + StreamPrintf(Stream *, const char *,...); extern int -StreamGetc(Stream *); + StreamGetc(Stream *); extern int -StreamUngetc(Stream *, int); + StreamUngetc(Stream *, int); extern int -StreamPutc(Stream *, int); + StreamPutc(Stream *, int); extern int -StreamEof(Stream *); + StreamEof(Stream *); extern int -StreamError(Stream *); + StreamError(Stream *); extern void -StreamClearError(Stream *); + StreamClearError(Stream *); extern int -StreamFlush(Stream *); + StreamFlush(Stream *); extern ssize_t -StreamCopy(Stream *, Stream *); + StreamCopy(Stream *, Stream *); -#endif /* TELODENDRIA_STREAM_H */ +#endif /* TELODENDRIA_STREAM_H */