aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2021-10-26 22:22:50 +0200
committerJeremias Stotter <jeremias@stotter.eu>2021-10-26 22:22:50 +0200
commit2a4db84cfc076b2df2030efa22985a80c62ec8f1 (patch)
treecf1505363d09821291721f07c4e72d23aaf5d9b8
parenta7186b411a899dc471fd4e1f71b7f7aabe575153 (diff)
downloadJBlog-2a4db84cfc076b2df2030efa22985a80c62ec8f1.tar.gz
JBlog-2a4db84cfc076b2df2030efa22985a80c62ec8f1.tar.bz2
JBlog-2a4db84cfc076b2df2030efa22985a80c62ec8f1.zip
Allow manual cache dropping
By simply adding /! to the end of a request Also update readme.html to reflect recent changes
-rw-r--r--jblog.c34
-rw-r--r--makefile2
-rw-r--r--readme.html3
3 files changed, 31 insertions, 8 deletions
diff --git a/jblog.c b/jblog.c
index 4cb2a35..df963a2 100644
--- a/jblog.c
+++ b/jblog.c
@@ -29,6 +29,7 @@
#include <sys/mman.h>
#include <signal.h>
#include <string.h>
+#include <stdbool.h>
#include "md.h"
@@ -79,7 +80,7 @@ char* base_path;
int pattern_type = 0;
int handle_request(int socket);
-int create_html(char* content, size_t content_length, char request_uri[1024], char request_method[64], char** buffer, size_t* reply_size);
+int create_html(char* content, size_t content_length, char request_uri[1024], char request_method[64], char** buffer, size_t* reply_size, bool ignore_cache);
int seperate_string(char* input, char* seperator, char** out_pre, char** out_post);
int main(int argc, char* argv[]) {
@@ -280,11 +281,19 @@ int handle_request(int socket) {
fprintf(stderr, "WARNING: message read from socket was shortet than expected\n");
}
}
+ // If the request ends with /! we ignore entries already in the cache
+ // This can be usefull in case you change a blog file and will safe you from restarting the server
+ bool ignore_cache = false;
+ size_t request_uri_len = strlen(request_uri);
+ if(request_uri[request_uri_len-2] == '/' && request_uri[request_uri_len-1] == '!') {
+ ignore_cache = true;
+ request_uri[request_uri_len-2] = '\0';
+ }
// Create and return the html
char* html;
char http_response[MAX_REPLY] = "";
size_t reply_size = 0;
- int status_code = create_html(content, content_length, request_uri, request_method, &html, &reply_size);
+ int status_code = create_html(content, content_length, request_uri, request_method, &html, &reply_size, ignore_cache);
if(status_code > 299 || status_code < 200) {
free(html);
}
@@ -427,7 +436,7 @@ char* read_jblog_file(char* file_name, int* error_code, char* title_buffer, size
// This will create the html in buffer and return a http status code
// It will also alocate the buffer itself
// The buffer should only be freed by the caller in case the return isn't in the 200-299 success range
-int create_html(char* content, size_t content_length, char request_uri[1024], char request_method[64], char** buffer, size_t* reply_size) {
+int create_html(char* content, size_t content_length, char request_uri[1024], char request_method[64], char** buffer, size_t* reply_size, bool ignore_cache) {
*buffer = malloc(MAX_REPLY);
if(buffer == NULL) {
@@ -453,9 +462,20 @@ int create_html(char* content, size_t content_length, char request_uri[1024], ch
struct tree_entry** found_entry = tfind(in_entry, &tree_root, compare);
if(found_entry != NULL) {
- free(*buffer);
- *buffer = (*found_entry)->content;
- return 200;
+ if(ignore_cache) {
+ // If we ignore the cache we just free the old entry
+ printf("Cache drop\n");
+ free((*found_entry)->content);
+ struct tree_entry* free_entry = *found_entry;
+ if(tdelete(in_entry, &tree_root, compare) == NULL) {
+ printf("BULLSHIT!!!\n");
+ }
+ free(free_entry);
+ } else {
+ free(*buffer);
+ *buffer = (*found_entry)->content;
+ return 200;
+ }
}
int error_code = 0;
@@ -495,7 +515,7 @@ int create_html(char* content, size_t content_length, char request_uri[1024], ch
free(dyn_content);
return 500;
}
-
+
memcpy(*found_entry, in_entry, sizeof(struct tree_entry));
// @todo handle all the different inputs
diff --git a/makefile b/makefile
index 0c96778..fd95387 100644
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
CC=gcc
-CFLAGS=-O2 -std=c99 -Wall -g -Wno-unused-variable
+CFLAGS=-O2 -std=c99 -Wall -g
jblog: jblog.c md.o
$(CC) $(CFLAGS) jblog.c md.o -o $@
diff --git a/readme.html b/readme.html
index c573508..407fc05 100644
--- a/readme.html
+++ b/readme.html
@@ -1,5 +1,6 @@
<h1>JBlog</h1>
<p>This is a blog that interfaces with a webserver via SCGI. I have been thinking about writing some articles realted to Linux, System administration an the likes and so I thought that writing the backend myself is just appropriate.</p>
+<p>JBlog implements a Markdown engine and a memory cache for already computed entries.</p>
<h2>Building</h2>
<p>To build this project just run make. There aren't any special dependencies, as long as you hava a relatively recent C compiler and POSIX compatible system you should be good to go!</p>
<h2>Running</h2>
@@ -20,6 +21,8 @@
<h3>blog Index files</h3>
<p>Obviously a blog is no good if you cant find other entries, so there are index files. JBLOG will server a list of blog entries that match what a few criteria specified in the index file. (For example subdirectory)</p>
<p><b><em>NOTE: This is not yet implemented</b></em></p>
+<h3>Updating cached entries</h3>
+<p>JBlog caches already computed entries. Because it wouldn't be very useful restarting the server everytime you update a blog entry simply add <code>/!</code> to the end of the URL in your Browser. This will tell JBlog to recompute the requested file.</p>
<h2>Plans</h2>
<p>I've already mentioned a few planned features above, but here is a more complete list of the things planned for this:</p>
<ul>
Jeremias Stotters git repositories generated by CGIT