forked from Telodendria/Telodendria
Renamed String.h to Str.h because Windows is dumb.
This commit is contained in:
parent
148706b517
commit
30c3690287
11 changed files with 50 additions and 50 deletions
20
src/Db.c
20
src/Db.c
|
@ -26,7 +26,7 @@
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -201,7 +201,7 @@ DbHashKey(Array * args)
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(args); i++)
|
for (i = 0; i < ArraySize(args); i++)
|
||||||
{
|
{
|
||||||
char *tmp = StringConcat(2, str, ArrayGet(args, i));
|
char *tmp = StrConcat(2, str, ArrayGet(args, i));
|
||||||
|
|
||||||
Free(str);
|
Free(str);
|
||||||
str = tmp;
|
str = tmp;
|
||||||
|
@ -214,13 +214,13 @@ static char *
|
||||||
DbDirName(Db * db, Array * args)
|
DbDirName(Db * db, Array * args)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char *str = StringConcat(2, db->dir, "/");
|
char *str = StrConcat(2, db->dir, "/");
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(args) - 1; i++)
|
for (i = 0; i < ArraySize(args) - 1; i++)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = StringConcat(3, str, ArrayGet(args, i), "/");
|
tmp = StrConcat(3, str, ArrayGet(args, i), "/");
|
||||||
|
|
||||||
Free(str);
|
Free(str);
|
||||||
|
|
||||||
|
@ -234,12 +234,12 @@ static char *
|
||||||
DbFileName(Db * db, Array * args)
|
DbFileName(Db * db, Array * args)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char *str = StringConcat(2, db->dir, "/");
|
char *str = StrConcat(2, db->dir, "/");
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(args); i++)
|
for (i = 0; i < ArraySize(args); i++)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *arg = StringDuplicate(ArrayGet(args, i));
|
char *arg = StrDuplicate(ArrayGet(args, i));
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
|
|
||||||
/* Sanitize name to prevent directory traversal attacks */
|
/* Sanitize name to prevent directory traversal attacks */
|
||||||
|
@ -259,8 +259,8 @@ DbFileName(Db * db, Array * args)
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = StringConcat(3, str, arg,
|
tmp = StrConcat(3, str, arg,
|
||||||
(i < ArraySize(args) - 1) ? "/" : ".json");
|
(i < ArraySize(args) - 1) ? "/" : ".json");
|
||||||
|
|
||||||
Free(arg);
|
Free(arg);
|
||||||
Free(str);
|
Free(str);
|
||||||
|
@ -504,11 +504,11 @@ DbLockFromArr(Db * db, Array * args)
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(args); i++)
|
for (i = 0; i < ArraySize(args); i++)
|
||||||
{
|
{
|
||||||
ArrayAdd(name, StringDuplicate(ArrayGet(args, i)));
|
ArrayAdd(name, StrDuplicate(ArrayGet(args, i)));
|
||||||
}
|
}
|
||||||
ref->name = name;
|
ref->name = name;
|
||||||
|
|
||||||
HashMapSet(db->cache, StringDuplicate(hash), ref);
|
HashMapSet(db->cache, StrDuplicate(hash), ref);
|
||||||
db->cacheSize += ref->size;
|
db->cacheSize += ref->size;
|
||||||
|
|
||||||
ref->next = NULL;
|
ref->next = NULL;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
|
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -486,7 +486,7 @@ JsonDecodeString(FILE * in)
|
||||||
|
|
||||||
/* Encode the 4-byte UTF-8 buffer into a series
|
/* Encode the 4-byte UTF-8 buffer into a series
|
||||||
* of 1-byte characters */
|
* of 1-byte characters */
|
||||||
utf8Ptr = StringUtf8Encode(utf8);
|
utf8Ptr = StrUtf8Encode(utf8);
|
||||||
if (!utf8Ptr)
|
if (!utf8Ptr)
|
||||||
{
|
{
|
||||||
/* Mem error */
|
/* Mem error */
|
||||||
|
@ -494,8 +494,8 @@ JsonDecodeString(FILE * in)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the output of StringUtf8Encode() into
|
/* Move the output of StrUtf8Encode() into our
|
||||||
* our local buffer */
|
* local buffer */
|
||||||
strcpy(a, utf8Ptr);
|
strcpy(a, utf8Ptr);
|
||||||
Free(utf8Ptr);
|
Free(utf8Ptr);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <HttpServer.h>
|
#include <HttpServer.h>
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
#include <Routes.h>
|
#include <Routes.h>
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
}
|
}
|
||||||
|
|
||||||
pathParts = MATRIX_PATH_CREATE();
|
pathParts = MATRIX_PATH_CREATE();
|
||||||
requestPathCpy = StringDuplicate(requestPath);
|
requestPathCpy = StrDuplicate(requestPath);
|
||||||
key = requestPathCpy;
|
key = requestPathCpy;
|
||||||
|
|
||||||
while ((pathPart = strtok_r(key, "/", &key)))
|
while ((pathPart = strtok_r(key, "/", &key)))
|
||||||
|
@ -295,8 +295,8 @@ MatrixErrorCreate(MatrixError errorArg)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMapSet(errorObj, "errcode", JsonValueString(StringDuplicate(errcode)));
|
HashMapSet(errorObj, "errcode", JsonValueString(StrDuplicate(errcode)));
|
||||||
HashMapSet(errorObj, "error", JsonValueString(StringDuplicate(error)));
|
HashMapSet(errorObj, "error", JsonValueString(StrDuplicate(error)));
|
||||||
|
|
||||||
return errorObj;
|
return errorObj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
ROUTE_IMPL(RouteLogin, args)
|
ROUTE_IMPL(RouteLogin, args)
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,7 @@ ROUTE_IMPL(RouteLogin, args)
|
||||||
pwdFlow = HashMapCreate();
|
pwdFlow = HashMapCreate();
|
||||||
|
|
||||||
HashMapSet(pwdFlow, "type",
|
HashMapSet(pwdFlow, "type",
|
||||||
JsonValueString(StringDuplicate("m.login.password")));
|
JsonValueString(StrDuplicate("m.login.password")));
|
||||||
ArrayAdd(enabledFlows, JsonValueObject(pwdFlow));
|
ArrayAdd(enabledFlows, JsonValueObject(pwdFlow));
|
||||||
HashMapSet(response, "flows", JsonValueArray(enabledFlows));
|
HashMapSet(response, "flows", JsonValueArray(enabledFlows));
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
ROUTE_IMPL(RouteMatrix, args)
|
ROUTE_IMPL(RouteMatrix, args)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ ROUTE_IMPL(RouteMatrix, args)
|
||||||
|
|
||||||
Free(pathPart);
|
Free(pathPart);
|
||||||
|
|
||||||
ArrayAdd(versions, JsonValueString(StringDuplicate("v1.5")));
|
ArrayAdd(versions, JsonValueString(StrDuplicate("v1.5")));
|
||||||
|
|
||||||
response = HashMapCreate();
|
response = HashMapCreate();
|
||||||
HashMapSet(response, "versions", JsonValueArray(versions));
|
HashMapSet(response, "versions", JsonValueArray(versions));
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
|
|
||||||
#include <User.h>
|
#include <User.h>
|
||||||
|
@ -84,7 +84,7 @@ ROUTE_IMPL(RouteRegister, args)
|
||||||
response = MatrixErrorCreate(M_BAD_JSON);
|
response = MatrixErrorCreate(M_BAD_JSON);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
username = StringDuplicate(JsonValueAsString(val));
|
username = StrDuplicate(JsonValueAsString(val));
|
||||||
|
|
||||||
if (!UserValidate(username, args->matrixArgs->config->serverName))
|
if (!UserValidate(username, args->matrixArgs->config->serverName))
|
||||||
{
|
{
|
||||||
|
@ -135,7 +135,7 @@ ROUTE_IMPL(RouteRegister, args)
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
password = StringDuplicate(JsonValueAsString(val));
|
password = StrDuplicate(JsonValueAsString(val));
|
||||||
|
|
||||||
val = HashMapGet(request, "device_id");
|
val = HashMapGet(request, "device_id");
|
||||||
if (val)
|
if (val)
|
||||||
|
@ -147,7 +147,7 @@ ROUTE_IMPL(RouteRegister, args)
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceId = StringDuplicate(JsonValueAsString(val));
|
deviceId = StrDuplicate(JsonValueAsString(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
val = HashMapGet(request, "inhibit_login");
|
val = HashMapGet(request, "inhibit_login");
|
||||||
|
@ -173,7 +173,7 @@ ROUTE_IMPL(RouteRegister, args)
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialDeviceDisplayName = StringDuplicate(JsonValueAsString(val));
|
initialDeviceDisplayName = StrDuplicate(JsonValueAsString(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
val = HashMapGet(request, "refresh_token");
|
val = HashMapGet(request, "refresh_token");
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
ROUTE_IMPL(RouteWellKnown, args)
|
ROUTE_IMPL(RouteWellKnown, args)
|
||||||
{
|
{
|
||||||
|
@ -53,14 +53,14 @@ ROUTE_IMPL(RouteWellKnown, args)
|
||||||
|
|
||||||
response = HashMapCreate();
|
response = HashMapCreate();
|
||||||
|
|
||||||
HashMapSet(homeserver, "base_url", JsonValueString(StringDuplicate(args->matrixArgs->config->baseUrl)));
|
HashMapSet(homeserver, "base_url", JsonValueString(StrDuplicate(args->matrixArgs->config->baseUrl)));
|
||||||
HashMapSet(response, "m.homeserver", JsonValueObject(homeserver));
|
HashMapSet(response, "m.homeserver", JsonValueObject(homeserver));
|
||||||
|
|
||||||
if (args->matrixArgs->config->identityServer)
|
if (args->matrixArgs->config->identityServer)
|
||||||
{
|
{
|
||||||
HashMap *identityServer = HashMapCreate();
|
HashMap *identityServer = HashMapCreate();
|
||||||
|
|
||||||
HashMapSet(identityServer, "base_url", JsonValueString(StringDuplicate(args->matrixArgs->config->identityServer)));
|
HashMapSet(identityServer, "base_url", JsonValueString(StrDuplicate(args->matrixArgs->config->identityServer)));
|
||||||
HashMapSet(response, "m.identity_server", identityServer);
|
HashMapSet(response, "m.identity_server", identityServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
|
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
char *
|
char *
|
||||||
StringUtf8Encode(unsigned long utf8)
|
StrUtf8Encode(unsigned long utf8)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ StringUtf8Encode(unsigned long utf8)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
StringDuplicate(const char *inStr)
|
StrDuplicate(const char *inStr)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *outStr;
|
char *outStr;
|
||||||
|
@ -100,7 +100,7 @@ StringDuplicate(const char *inStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
StringConcat(size_t nStr,...)
|
StrConcat(size_t nStr,...)
|
||||||
{
|
{
|
||||||
va_list argp;
|
va_list argp;
|
||||||
char *str;
|
char *str;
|
||||||
|
@ -150,7 +150,7 @@ StringConcat(size_t nStr,...)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
StringRandom(size_t len)
|
StrRandom(size_t len)
|
||||||
{
|
{
|
||||||
static const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
static const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
static pthread_mutex_t seedLock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t seedLock = PTHREAD_MUTEX_INITIALIZER;
|
|
@ -27,7 +27,7 @@
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <Log.h>
|
#include <Log.h>
|
||||||
#include <Array.h>
|
#include <Array.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
#include <Db.h>
|
#include <Db.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CONFIG_COPY_STRING(into) \
|
#define CONFIG_COPY_STRING(into) \
|
||||||
into = StringDuplicate(JsonValueAsString(value));
|
into = StrDuplicate(JsonValueAsString(value));
|
||||||
|
|
||||||
#define CONFIG_OPTIONAL_STRING(into, key, default) \
|
#define CONFIG_OPTIONAL_STRING(into, key, default) \
|
||||||
value = HashMapGet(config, key); \
|
value = HashMapGet(config, key); \
|
||||||
|
@ -64,12 +64,12 @@
|
||||||
Log(lc, LOG_ERR, "Expected " key " to be of type JSON_STRING"); \
|
Log(lc, LOG_ERR, "Expected " key " to be of type JSON_STRING"); \
|
||||||
goto error; \
|
goto error; \
|
||||||
} \
|
} \
|
||||||
into = StringDuplicate(JsonValueAsString(value)); \
|
into = StrDuplicate(JsonValueAsString(value)); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
Log(lc, LOG_INFO, "Using default value " #default " for " key "."); \
|
Log(lc, LOG_INFO, "Using default value " #default " for " key "."); \
|
||||||
into = default ? StringDuplicate(default) : NULL; \
|
into = default ? StrDuplicate(default) : NULL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CONFIG_OPTIONAL_INTEGER(into, key, default) \
|
#define CONFIG_OPTIONAL_INTEGER(into, key, default) \
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <UserInteractiveAuth.h>
|
#include <UserInteractiveAuth.h>
|
||||||
|
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include <String.h>
|
#include <Str.h>
|
||||||
#include <Matrix.h>
|
#include <Matrix.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -38,7 +38,7 @@ BuildDummyFlow(void)
|
||||||
Array *flows = ArrayCreate();
|
Array *flows = ArrayCreate();
|
||||||
|
|
||||||
ArrayAdd(stages,
|
ArrayAdd(stages,
|
||||||
JsonValueString(StringDuplicate("m.login.dummy")));
|
JsonValueString(StrDuplicate("m.login.dummy")));
|
||||||
HashMapSet(dummyFlow, "stages", JsonValueArray(stages));
|
HashMapSet(dummyFlow, "stages", JsonValueArray(stages));
|
||||||
ArrayAdd(flows, JsonValueObject(dummyFlow));
|
ArrayAdd(flows, JsonValueObject(dummyFlow));
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ UserInteractiveAuth(HttpServerContext * context, Db * db,
|
||||||
{
|
{
|
||||||
HashMap *response = NULL;
|
HashMap *response = NULL;
|
||||||
HashMap *persist;
|
HashMap *persist;
|
||||||
char *session = StringRandom(24);
|
char *session = StrRandom(24);
|
||||||
|
|
||||||
ref = DbLock(db, 1, "user_interactive");
|
ref = DbLock(db, 1, "user_interactive");
|
||||||
if (!ref)
|
if (!ref)
|
||||||
|
@ -84,7 +84,7 @@ UserInteractiveAuth(HttpServerContext * context, Db * db,
|
||||||
response = BuildDummyFlow();
|
response = BuildDummyFlow();
|
||||||
|
|
||||||
HashMapSet(response, "session",
|
HashMapSet(response, "session",
|
||||||
JsonValueString(StringDuplicate(session)));
|
JsonValueString(StrDuplicate(session)));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,21 +21,21 @@
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef TELODENDRIA_STRING_H
|
#ifndef TELODENDRIA_STR_H
|
||||||
#define TELODENDRIA_STRING_H
|
#define TELODENDRIA_STR_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
StringUtf8Encode(unsigned long);
|
StrUtf8Encode(unsigned long);
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
StringDuplicate(const char *);
|
StrDuplicate(const char *);
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
StringConcat(size_t,...);
|
StrConcat(size_t,...);
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
StringRandom(size_t);
|
StrRandom(size_t);
|
||||||
|
|
||||||
#endif /* TELODENDRIA_STRING_H */
|
#endif /* TELODENDRIA_STR_H */
|
Loading…
Reference in a new issue