Rename etc dump to bakedres dump
This commit is contained in:
@ -5,7 +5,7 @@ how the code is architectured and some cool tricks that are used throughout the
|
||||
|
||||
## Our "engine"
|
||||
|
||||

|
||||

|
||||
|
||||
This image is a joke, obviously.
|
||||
|
||||
@ -133,7 +133,7 @@ void *route_thread_function(void *param)
|
||||
// Unparsable HTTP request
|
||||
}
|
||||
|
||||
if (mg_match(http_msg.uri, mg_str("/etc/*"), nil)) {
|
||||
if (mg_match(http_msg.uri, mg_str("/bakedres/*"), nil)) {
|
||||
// Request for static resource
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ this functionality comes with mongoose built-in. God bless you mongoose!
|
||||
|
||||
## Dynamic pages and static assets.
|
||||
|
||||

|
||||

|
||||
|
||||
Let's stop here now and talk about something different entirely (dont' worry, we'll come back later).
|
||||
I'd like to show you how assets/pages are implemented in aboba, so we get the whole picture.
|
||||
|
64
main.c
64
main.c
@ -18,7 +18,7 @@
|
||||
#include "locked.h"
|
||||
|
||||
static locked(Route *) route_hashtable = locked_init(nil);
|
||||
static locked(char *) etc_dump_path = locked_init(nil);
|
||||
static locked(char *) baked_dump_path = locked_init(nil);
|
||||
|
||||
void run_in_thread(void *(*f)(void *), void *p)
|
||||
{
|
||||
@ -49,7 +49,7 @@ void *route_thread_function(void *param)
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (mg_match(http_msg.uri, mg_str("/etc/*"), nil)) {
|
||||
if (mg_match(http_msg.uri, mg_str("/bakedres/*"), nil)) {
|
||||
Route_Result result = {0};
|
||||
result.type = ROUTE_RESULT_STATIC;
|
||||
|
||||
@ -60,9 +60,9 @@ void *route_thread_function(void *param)
|
||||
char *file = basename(p);
|
||||
char *full_path = malloc(PATH_MAX);
|
||||
|
||||
lockx(&etc_dump_path);
|
||||
snprintf(full_path, PATH_MAX, "%s/%s", etc_dump_path.value, file);
|
||||
unlockx(&etc_dump_path);
|
||||
lockx(&baked_dump_path);
|
||||
snprintf(full_path, PATH_MAX, "%s/%s", baked_dump_path.value, file);
|
||||
unlockx(&baked_dump_path);
|
||||
|
||||
sb_append_nstr(&result.body, full_path);
|
||||
sb_finish(&result.body);
|
||||
@ -165,23 +165,23 @@ void free_route_hashtable(void)
|
||||
unlockx(&route_hashtable);
|
||||
}
|
||||
|
||||
char *init_etc_dump(void)
|
||||
char *init_baked_dump(void)
|
||||
{
|
||||
char template[] = "/tmp/aboba-etc.XXXXXX";
|
||||
char *etc_dump1 = mkdtemp(template);
|
||||
char *etc_dump = malloc(strlen(etc_dump1)+1);
|
||||
strcpy(etc_dump, etc_dump1);
|
||||
char template[] = "/tmp/aboba-bakedres.XXXXXX";
|
||||
char *baked_dump1 = mkdtemp(template);
|
||||
char *baked_dump = malloc(strlen(baked_dump1)+1);
|
||||
strcpy(baked_dump, baked_dump1);
|
||||
|
||||
if (etc_dump == nil) {
|
||||
LOGE("Could not create etc dump\n");
|
||||
if (baked_dump == nil) {
|
||||
LOGE("Could not create bakedres dump\n");
|
||||
return nil;
|
||||
}
|
||||
LOGI("etc dump dir is %s\n", etc_dump);
|
||||
LOGI("bakedres dump dir is %s\n", baked_dump);
|
||||
|
||||
return etc_dump;
|
||||
return baked_dump;
|
||||
}
|
||||
|
||||
int etc_dump_rm_cb(const char *path,
|
||||
int baked_dump_rm_cb(const char *path,
|
||||
discard const struct stat *st,
|
||||
discard int type,
|
||||
discard struct FTW *ftw)
|
||||
@ -189,14 +189,14 @@ int etc_dump_rm_cb(const char *path,
|
||||
return remove(path);
|
||||
}
|
||||
|
||||
bool free_etc_dump(char *etc_dump)
|
||||
bool free_baked_dump(char *baked_dump)
|
||||
{
|
||||
LOGI("Removing etc dump %s\n", etc_dump);
|
||||
bool ok = nftw(etc_dump, etc_dump_rm_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) != -1;
|
||||
LOGI("Removing bakedres dump %s\n", baked_dump);
|
||||
bool ok = nftw(baked_dump, baked_dump_rm_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) != -1;
|
||||
if (!ok) {
|
||||
LOGE("Could not remove %s\n", etc_dump);
|
||||
LOGE("Could not remove %s\n", baked_dump);
|
||||
}
|
||||
free(etc_dump);
|
||||
free(baked_dump);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -234,20 +234,20 @@ int cp(const char* source, const char* destination)
|
||||
return result;
|
||||
}
|
||||
|
||||
void copy_baked_resources_to_etc_dump(Baked_Resource *resource, void *udata)
|
||||
void copy_baked_resources_to_baked_dump(Baked_Resource *resource, void *udata)
|
||||
{
|
||||
char *etc_dump = (char *)udata;
|
||||
char *baked_dump = (char *)udata;
|
||||
char path[PATH_MAX];
|
||||
get_baked_resource_path(resource->key, path, sizeof(path));
|
||||
char dest[PATH_MAX];
|
||||
snprintf(dest, sizeof(dest), "%s/%s", etc_dump, resource->key);
|
||||
snprintf(dest, sizeof(dest), "%s/%s", baked_dump, resource->key);
|
||||
cp(path, dest);
|
||||
}
|
||||
|
||||
void populate_etc_dump(char *etc_dump)
|
||||
void populate_baked_dump(char *baked_dump)
|
||||
{
|
||||
lock_baked_resources();
|
||||
baked_resource_each(©_baked_resources_to_etc_dump, etc_dump);
|
||||
baked_resource_each(©_baked_resources_to_baked_dump, baked_dump);
|
||||
unlock_baked_resources();
|
||||
}
|
||||
|
||||
@ -261,12 +261,12 @@ int main(int argc, char ** argv)
|
||||
start_timer();
|
||||
|
||||
init_baked_resources();
|
||||
lockx(&etc_dump_path);
|
||||
if ((etc_dump_path.value = init_etc_dump()) == nil) {
|
||||
lockx(&baked_dump_path);
|
||||
if ((baked_dump_path.value = init_baked_dump()) == nil) {
|
||||
return 1;
|
||||
}
|
||||
populate_etc_dump(etc_dump_path.value);
|
||||
unlockx(&etc_dump_path);
|
||||
populate_baked_dump(baked_dump_path.value);
|
||||
unlockx(&baked_dump_path);
|
||||
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
struct mg_mgr mgr;
|
||||
@ -284,9 +284,9 @@ int main(int argc, char ** argv)
|
||||
|
||||
mg_mgr_free(&mgr);
|
||||
|
||||
lockx(&etc_dump_path);
|
||||
free_etc_dump(etc_dump_path.value);
|
||||
unlockx(&etc_dump_path);
|
||||
lockx(&baked_dump_path);
|
||||
free_baked_dump(baked_dump_path.value);
|
||||
unlockx(&baked_dump_path);
|
||||
free_baked_resources();
|
||||
|
||||
return 0;
|
||||
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<title>Blog</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/etc/simple.css" />
|
||||
<link rel="stylesheet" href="/bakedres/simple.css" />
|
||||
<#META_TAGS>
|
||||
</head>
|
||||
<body>
|
||||
@ -24,8 +24,8 @@
|
||||
</footer>
|
||||
|
||||
<#ifdef HOTRELOAD>
|
||||
<script src="/etc/hotreload.js"></script>
|
||||
<script src="/bakedres/hotreload.js"></script>
|
||||
<#endif>
|
||||
<script src="/etc/theme.js"></script>
|
||||
<script src="/bakedres/theme.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<title>Kamil's personal website</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/etc/simple.css" />
|
||||
<link rel="stylesheet" href="/bakedres/simple.css" />
|
||||
<#META_TAGS>
|
||||
</head>
|
||||
<body>
|
||||
@ -54,7 +54,7 @@
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<img src="/etc/me.jpg" alt="literally me" />
|
||||
<img src="/bakedres/me.jpg" alt="literally me" />
|
||||
</section>
|
||||
<footer>
|
||||
<div style="float: left;">
|
||||
@ -65,8 +65,8 @@
|
||||
</footer>
|
||||
|
||||
<#ifdef HOTRELOAD>
|
||||
<script src="/etc/hotreload.js"></script>
|
||||
<script src="/bakedres/hotreload.js"></script>
|
||||
<#endif>
|
||||
<script src="/etc/theme.js"></script>
|
||||
<script src="/bakedres/theme.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>404 - Page not found</title>
|
||||
<link rel="stylesheet" href="/etc/simple.css" />
|
||||
<link rel="stylesheet" href="/bakedres/simple.css" />
|
||||
<#META_TAGS>
|
||||
</head>
|
||||
<body>
|
||||
@ -19,8 +19,8 @@
|
||||
</footer>
|
||||
|
||||
<#ifdef HOTRELOAD>
|
||||
<script src="/etc/hotreload.js"></script>
|
||||
<script src="/bakedres/hotreload.js"></script>
|
||||
<#endif>
|
||||
<script src="/etc/theme.js"></script>
|
||||
<script src="/bakedres/theme.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,10 +3,10 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title><#BLOG_POST_TITLE></title>
|
||||
<link rel="stylesheet" href="/etc/simple.css" />
|
||||
<link rel="stylesheet" href="/bakedres/simple.css" />
|
||||
<#META_TAGS>
|
||||
<link rel="stylesheet" href="/etc/hljs-rainbow.css">
|
||||
<script src="/etc/highlight.js"></script>
|
||||
<link rel="stylesheet" href="/bakedres/hljs-rainbow.css">
|
||||
<script src="/bakedres/highlight.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content"></div>
|
||||
@ -23,9 +23,9 @@
|
||||
</script>
|
||||
|
||||
<#ifdef HOTRELOAD>
|
||||
<script src="/etc/hotreload.js"></script>
|
||||
<script src="/bakedres/hotreload.js"></script>
|
||||
<#endif>
|
||||
<script src="/etc/theme.js"></script>
|
||||
<script src="/bakedres/theme.js"></script>
|
||||
<script>hljs.highlightAll();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user