diff --git a/.gitignore b/.gitignore
index 8ef8c0f..a3cc331 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
-file-to-c
+filec
**/*.cgi
**/*.o
-**/*.chtml
\ No newline at end of file
+**/*.chtml
+mastodont
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 96cb5c3..8f6bc0b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,9 @@
CC ?= cc
GIT ?= git
-CFLAGS = -Wall
-LDFLAGS = -lcurl
+MASTODONT_DIR = mastodont/
+MASTODONT = $(MASTODONT_DIR)libmastodont.a
+CFLAGS = -Wall -I $(MASTODONT)include/
+LDFLAGS = -L$(MASTODONT_DIR) -lcurl -lmastodont
SRC = $(wildcard src/*.c)
OBJ = $(patsubst %.c,%.o,$(SRC))
PAGES_DIR = static
@@ -10,28 +12,23 @@ PAGES_CMP = $(patsubst %.html,%.chtml,$(PAGES))
DIST = dist/
TARGET = ratfe.cgi
-# Mastodont
-MASTODONT = mastodont/
-MASTODONT_REPO = https://git.nekobit.net/repos/mastodont-c.git
-
-all: mastodont $(TARGET)
-mastodont: $(MASTODONT)
+all: $(MASTODONT) $(TARGET)
$(TARGET): filec $(PAGES_CMP) $(OBJ)
$(CC) -o $(DIST)$(TARGET) $(LDFLAGS) $(OBJ)
filec: src/file-to-c/main.o
- $(CC) -o file-to-c $<
+ $(CC) -o filec $<
%.chtml: %.html
- ./file-to-c $< $< > $@
+ ./filec $< $< > $@
$(PAGES_DIR)/index.chtml: $(PAGES_DIR)/index.html
- ./file-to-c $< data_index_html > $@
+ ./filec $< data_index_html > $@
$(MASTODONT):
- $(GIT) submodule foreach git pull
- make -C $(MASTODONT)
+ $(GIT) submodule update --init --recursive
+ make -C $(MASTODONT_DIR)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
@@ -39,5 +36,6 @@ $(MASTODONT):
clean:
rm -f $(OBJ) src/file-to-c/main.o
rm -f $(PAGES_CMP)
+ rm -f filec
.PHONY: all filec clean
diff --git a/config.h b/config.h
index 3c2cdbb..1353af7 100644
--- a/config.h
+++ b/config.h
@@ -11,6 +11,26 @@
#define FALSE 0
#define TRUE 1
+/*
+ * String: config_canonical_name
+ *
+ * The software's recognizable name.
+ *
+ *
+ * Example: "RatFE"
+ */
+
static const char* config_canonical_name = "RatFE";
+/*
+ * String: config_instance_url
+ *
+ * The instances URL which all API calls will be sent to via mastodont-c.
+ * This MUST include a slash at the end, and the protocol (like https://) at the
+ * beginning
+ *
+ * Example: https://cum.desupost.soy/
+ */
+static const char* config_instance_url = "https://cum.desupost.soy/";
+
#endif // CONFIG_H
diff --git a/src/file-to-c/main.c b/src/file-to-c/main.c
new file mode 100644
index 0000000..faf2ecd
--- /dev/null
+++ b/src/file-to-c/main.c
@@ -0,0 +1,71 @@
+/*
+ * RatFE - Lightweight frontend for Pleroma
+ * Copyright (C) 2022 Nekobit
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+
+enum args
+{
+ ARG_FILENAME = 1,
+ ARG_VARIABLE
+};
+
+long filesize(FILE* file)
+{
+ long orig = ftell(file);
+ fseek(file, 0, SEEK_END);
+ long size = ftell(file);
+ fseek(file, orig, SEEK_SET);
+ return size;
+}
+
+int main(int argc, char** argv)
+{
+ char* buf;
+ FILE* file = fopen(argv[ARG_FILENAME], "rb");
+
+ long size = filesize(file);
+
+ if (!(buf = malloc(size)))
+ {
+ perror("malloc");
+ return 1;
+ }
+
+ if (fread(buf, 1, size, file) != size)
+ {
+ fputs("Didn't read correctly!", stderr);
+ free(buf);
+ return 1;
+ }
+
+ fclose(file);
+
+ printf("#ifndef __%s\n", argv[ARG_VARIABLE]);
+ printf("#define __%s\n", argv[ARG_VARIABLE]);
+ printf("static const char %s[] = {", argv[ARG_VARIABLE]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ printf("0X%hhX,", buf[i]);
+ }
+ puts("0};\n#endif");
+
+ free(buf);
+ return 0;
+}
diff --git a/src/main.c b/src/main.c
index 2d7e0a5..3cbf4cf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,6 +19,8 @@
#include
#include
#include
+#include
+#include "../config.h"
#include "index.h"
int main()
@@ -26,10 +28,17 @@ int main()
char* path = getenv("PATH_INFO");
// Content type is always HTML
fputs("Content-type: text/html\r\n\r\n", stdout);
+
+ mastodont_t api;
+ api.url = config_instance_url;
+
+ mastodont_init(&api);
// Default index
if (path == NULL || (path && strcmp(path, "/")))
{
content_index();
}
+
+ mastodont_free(&api);
}