Bug fixes

This commit is contained in:
2025-09-24 21:06:18 +02:00
parent 39ec510dbb
commit c9038b8fac
5 changed files with 27 additions and 28 deletions
+3
View File
@@ -1,4 +1,7 @@
# cWEB
cWEB is a framework for web development designed for small scale production environments and tooling. It's distributed as a single header file and has minimal dependencies.
cWEB is single header file web framework for C designed for small scale production environments and tooling :D
(In progress)
+10 -13
View File
@@ -1,8 +1,8 @@
/*
Copyright © 2025 Francesco Cozzuto
Copyright © 2025 Francesco Cozzuto
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the Software),
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
@@ -11,7 +11,7 @@ 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 substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS
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
@@ -14316,13 +14316,6 @@ void cweb_global_free(void)
CWEB *cweb_init(CWEB_String addr, uint16_t port)
{
// If set, allows logins and signups over HTTP, which is highly insecure.
// This allows compiling the application without TLS when developing.
bool allow_insecure_login = true;
if (allow_insecure_login)
printf("WARNING: allow_insecure_login is true\n");
CWEB *cweb = malloc(sizeof(CWEB));
if (cweb == NULL)
return NULL;
@@ -14370,7 +14363,12 @@ CWEB *cweb_init(CWEB_String addr, uint16_t port)
cweb->trace_sql = false;
#endif
cweb->allow_insecure_login = false;
// If set, allows logins and signups over HTTP, which is highly insecure.
// This allows compiling the application without TLS when developing.
cweb->allow_insecure_login = true;
if (cweb->allow_insecure_login)
printf("WARNING: allow_insecure_login is true\n");
return cweb;
}
@@ -14622,8 +14620,7 @@ int cweb_set_user_id(CWEB_Request *req, int user_id)
if (user_id == -1) ret = delete_session(req->cweb->session_storage, req->sess);
else ret = create_session(req->cweb->session_storage, user_id, &req->sess, &req->csrf);
if (ret < 0)
return -1;
if (ret < 0) return -1;
req->just_created_session = true;
}
+3 -1
View File
@@ -331,6 +331,8 @@ int main(void)
{
CWEB_String addr = CWEB_STR("127.0.0.1");
uint16_t port = 8080;
CWEB_String database_file = CWEB_STR(":memory:");
CWEB_String schema_file = CWEB_STR("demo/schema.sql");
if (cweb_global_init() < 0)
return -1;
@@ -341,7 +343,7 @@ int main(void)
return -1;
}
if (cweb_enable_database(cweb, CWEB_STR(":memory:"), CWEB_STR("demo/schema.sql")) < 0) {
if (cweb_enable_database(cweb, database_file, schema_file) < 0) {
cweb_free(cweb);
cweb_global_free();
return -1;
+4 -4
View File
@@ -1,7 +1,7 @@
include "page.wl"
let posts = $query("SELECT U.username, P.title, P.content FROM Posts as P, Users as U WHERE P.id=? AND U.id=P.author", $post_id)
let comments = $query("SELECT C.id, U.username, C.content, C.parent_post, C.parent_comment FROM Comments as C, Users as U WHERE C.parent_post=? AND U.id=C.author", $post_id)
let posts = $query("SELECT U.username, P.title, P.content FROM Posts as P, Users as U WHERE P.id=? AND U.id=P.author", $resource_id)
let comments = $query("SELECT C.id, U.username, C.content, C.parent_post, C.parent_comment FROM Comments as C, Users as U WHERE C.parent_post=? AND U.id=C.author", $resource_id)
let lookup = {}
@@ -193,7 +193,7 @@ let main =
</summary>
<div class="add-comment">
<form action="/api/comment" method="POST">
<input type="hidden" name="parent_post" value=\'"'\$post_id\'"' />
<input type="hidden" name="parent_post" value=\'"'\$resource_id\'"' />
<textarea name="content" placeholder="Add a comment..."></textarea>
<input type="submit" vaue="Publish" />
</form>
@@ -221,7 +221,7 @@ let main =
</summary>
<div class="add-comment">
<form action="/api/comment" method="POST">
<input type="hidden" name="parent_post" value=\'"'\$post_id\'"' />
<input type="hidden" name="parent_post" value=\'"'\$resource_id\'"' />
<input type="hidden" name="parent_comment" value=\'"'\comment.id\'"' />
<textarea name="content" placeholder="Add a comment..."></textarea>
<input type="submit" vaue="Publish" />
+7 -10
View File
@@ -928,13 +928,6 @@ void cweb_global_free(void)
CWEB *cweb_init(CWEB_String addr, uint16_t port)
{
// If set, allows logins and signups over HTTP, which is highly insecure.
// This allows compiling the application without TLS when developing.
bool allow_insecure_login = true;
if (allow_insecure_login)
printf("WARNING: allow_insecure_login is true\n");
CWEB *cweb = malloc(sizeof(CWEB));
if (cweb == NULL)
return NULL;
@@ -982,7 +975,12 @@ CWEB *cweb_init(CWEB_String addr, uint16_t port)
cweb->trace_sql = false;
#endif
cweb->allow_insecure_login = false;
// If set, allows logins and signups over HTTP, which is highly insecure.
// This allows compiling the application without TLS when developing.
cweb->allow_insecure_login = true;
if (cweb->allow_insecure_login)
printf("WARNING: allow_insecure_login is true\n");
return cweb;
}
@@ -1234,8 +1232,7 @@ int cweb_set_user_id(CWEB_Request *req, int user_id)
if (user_id == -1) ret = delete_session(req->cweb->session_storage, req->sess);
else ret = create_session(req->cweb->session_storage, user_id, &req->sess, &req->csrf);
if (ret < 0)
return -1;
if (ret < 0) return -1;
req->just_created_session = true;
}