aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
l---------NETWORKING.md1
-rw-r--r--c_implementation/Makefile.am27
-rwxr-xr-xc_implementation/build.sh (renamed from src/build.sh)0
-rwxr-xr-xc_implementation/build_tree/ak_fs_build.sh (renamed from src/build_tree/ak_fs_build.sh)6
-rwxr-xr-xc_implementation/build_tree/ak_log_build.sh (renamed from src/build_tree/ak_log_build.sh)10
-rwxr-xr-xc_implementation/build_tree/ak_logcatter_build.sh (renamed from src/build_tree/ak_logcatter_build.sh)4
-rwxr-xr-xc_implementation/build_tree/ak_settings_build.sh11
-rwxr-xr-xc_implementation/build_tree/ak_utils_build.sh7
-rwxr-xr-xc_implementation/build_tree/libsodium_test_build.sh1
-rw-r--r--c_implementation/configure.ac11
-rw-r--r--c_implementation/include/libakfs.h119
-rw-r--r--c_implementation/include/libaklog.h (renamed from src/include/aklog.h)10
-rw-r--r--c_implementation/include/libaklogcatter.h (renamed from src/include/aklogcatter.h)0
-rw-r--r--c_implementation/include/libaksettings.h25
-rw-r--r--c_implementation/include/libakutils.h24
-rw-r--r--c_implementation/src/akfs.c (renamed from src/akfs.c)25
-rw-r--r--c_implementation/src/aklog.c (renamed from src/aklog.c)92
-rw-r--r--c_implementation/src/aklogcatter.c (renamed from src/aklogcatter.c)4
-rw-r--r--c_implementation/src/aksettings.c113
-rw-r--r--c_implementation/src/akutils.c (renamed from src/aksettings.c)4
-rw-r--r--c_implementation/tests/test_akfs.c (renamed from src/tests/test_akfs.c)12
-rw-r--r--c_implementation/tests/test_akfs_mkdir.c (renamed from src/tests/test_akfs_mkdir.c)2
-rw-r--r--c_implementation/tests/test_aklog.c (renamed from src/tests/test_aklog.c)10
-rw-r--r--c_implementation/tests/test_aklogcatter.c (renamed from src/tests/test_aklogcatter.c)2
-rw-r--r--c_implementation/tests/test_aklogwrite.c16
-rw-r--r--c_implementation/tests/test_aksettings.c53
-rw-r--r--c_implementation/tests/test_aksettings_read.c23
-rw-r--r--c_implementation/tests/test_akutils.c7
-rw-r--r--c_implementation/tests/test_sha512_string.c70
-rwxr-xr-xsrc/build_tree/ak_settings_build.sh7
-rw-r--r--src/include/akfs.h25
-rw-r--r--src/include/aksettings.h6
-rwxr-xr-xsrc/new_lib.sh83
-rw-r--r--src/tests/test_aklogwrite.c13
-rw-r--r--src/tests/test_aksettings.c7
35 files changed, 616 insertions, 214 deletions
diff --git a/NETWORKING.md b/NETWORKING.md
deleted file mode 120000
index a3de44a..0000000
--- a/NETWORKING.md
+++ /dev/null
@@ -1 +0,0 @@
-NETWORKING \ No newline at end of file
diff --git a/c_implementation/Makefile.am b/c_implementation/Makefile.am
new file mode 100644
index 0000000..507550f
--- /dev/null
+++ b/c_implementation/Makefile.am
@@ -0,0 +1,27 @@
+ACLOCAL_AMFLAGS = -I m4
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+
+# Link each test to the library
+#$(test_programs): % : %.c
+# $(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) libmylib.la
+#
+#
+# Build shared library from root dir sources
+
+lib_LTLIBRARIES = libaklog.la
+libaklog_la_SOURCES = $(top_srcdir)/src/aklog.c
+include_HEADERS = include/libaklog.h
+
+## Build tests (no SUBDIRS needed)
+check_PROGRAMS = test_aklog
+test_aklog_SOURCES = ./tests/test_aklog.c
+test_aklog_LDADD = libaklog.la
+tests_test_main_CPPFLAGS = -I$(top_srcdir)/include # For tests too
+
+# Enable 'make check' to run tests
+TESTS = $(check_PROGRAMS)
+
+# Optional: Clean test binaries aggressively
+CLEANFILES = $(TESTS)
+
diff --git a/src/build.sh b/c_implementation/build.sh
index 183f022..183f022 100755
--- a/src/build.sh
+++ b/c_implementation/build.sh
diff --git a/src/build_tree/ak_fs_build.sh b/c_implementation/build_tree/ak_fs_build.sh
index a18b824..11b4fde 100755
--- a/src/build_tree/ak_fs_build.sh
+++ b/c_implementation/build_tree/ak_fs_build.sh
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
echo "Building lib/akfs.so" && \
-gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include akfs.c -o lib/akfs.so && \
+gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include ./src/akfs.c -o lib/libakfs.so && \
echo "Building tests/test_akfs" && \
-gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_akfs.c lib/akfs.so -o tests/test_akfs && \
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_akfs.c lib/libakfs.so -o tests/test_akfs && \
echo "Running test_akfs" && \
time ./tests/test_akfs && \
rm ./tests/test_akfs
echo "Building tests/test_akfs_mkdir.c" && \
-gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_akfs_mkdir.c lib/akfs.so -o tests/test_akfs_mkdir && \
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_akfs_mkdir.c lib/libakfs.so -o tests/test_akfs_mkdir && \
echo "Running test_akfs_mkdir" && \
time ./tests/test_akfs_mkdir && \
rm ./tests/test_akfs_mkdir
diff --git a/src/build_tree/ak_log_build.sh b/c_implementation/build_tree/ak_log_build.sh
index ab83378..76a4113 100755
--- a/src/build_tree/ak_log_build.sh
+++ b/c_implementation/build_tree/ak_log_build.sh
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
echo "Building lib/aklog.so" && \
-gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include aklog.c -o lib/aklog.so && \
+gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include src/aklog.c -o lib/libaklog.so && \
echo "Building tests/test_aklog" && \
-gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aklog.c lib/aklog.so -o tests/test_aklog && \
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aklog.c lib/libaklog.so -o tests/test_aklog && \
echo "Running test_aklog" && \
-time ./tests/test_aklog && \
-rm ./tests/test_aklog
-gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aklogwrite.c lib/aklog.so -o tests/test_aklogwrite && \
+time ./tests/test_aklog # && \
+# rm ./tests/test_aklog
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aklogwrite.c lib/libaklog.so -o tests/test_aklogwrite && \
echo "Running test_aklogwrite" && \
time ./tests/test_aklogwrite && \
rm ./tests/test_aklogwrite
diff --git a/src/build_tree/ak_logcatter_build.sh b/c_implementation/build_tree/ak_logcatter_build.sh
index 5038073..aa321cb 100755
--- a/src/build_tree/ak_logcatter_build.sh
+++ b/c_implementation/build_tree/ak_logcatter_build.sh
@@ -1,7 +1,7 @@
echo "Building lib/aklogcatter.so" && \
-gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include aklogcatter.c -o lib/aklogcatter.so && \
+gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include src/aklogcatter.c -o lib/libaklogcatter.so && \
echo "Building tests/test_aklogcatter" && \
-gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aklogcatter.c lib/aklog.so lib/aklogcatter.so -o tests/test_aklogcatter && \
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aklogcatter.c lib/libaklog.so lib/libaklogcatter.so -o tests/test_aklogcatter && \
echo "Running test_aklogcatter" && \
time ./tests/test_aklogcatter && \
rm ./tests/test_aklogcatter
diff --git a/c_implementation/build_tree/ak_settings_build.sh b/c_implementation/build_tree/ak_settings_build.sh
new file mode 100755
index 0000000..f5137f9
--- /dev/null
+++ b/c_implementation/build_tree/ak_settings_build.sh
@@ -0,0 +1,11 @@
+echo "Building lib/aksettings.so" && \
+gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include src/aksettings.c -o lib/libaksettings.so && \
+echo "Building tests/test_aksettings" && \
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aksettings.c lib/libaklog.so lib/libaksettings.so -o tests/test_aksettings && \
+echo "Running test_aksettings" && \
+time ./tests/test_aksettings && \
+rm ./tests/test_aksettings
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_aksettings_read.c lib/libaklog.so lib/libaksettings.so -o tests/test_aksettings_read && \
+echo "Running test_aksettings_read" && \
+time ./tests/test_aksettings_read && \
+rm ./tests/test_aksettings_read
diff --git a/c_implementation/build_tree/ak_utils_build.sh b/c_implementation/build_tree/ak_utils_build.sh
new file mode 100755
index 0000000..178519a
--- /dev/null
+++ b/c_implementation/build_tree/ak_utils_build.sh
@@ -0,0 +1,7 @@
+echo "Building lib/akutils.so" && \
+ gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include src/akutils.c -o lib/libakutils.so && \
+ echo "Building tests/test_akutils" && \
+ gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_akutils.c lib/libakutils.so -o tests/test_akutils && \
+ echo "Running test_akutils" && \
+ time ./tests/test_akutils && \
+ rm ./tests/test_akutils
diff --git a/c_implementation/build_tree/libsodium_test_build.sh b/c_implementation/build_tree/libsodium_test_build.sh
new file mode 100755
index 0000000..f427873
--- /dev/null
+++ b/c_implementation/build_tree/libsodium_test_build.sh
@@ -0,0 +1 @@
+gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include -lsodium tests/libsodium.c lib/libaklog.so -o watah
diff --git a/c_implementation/configure.ac b/c_implementation/configure.ac
new file mode 100644
index 0000000..477ec5c
--- /dev/null
+++ b/c_implementation/configure.ac
@@ -0,0 +1,11 @@
+AC_INIT([akt], [0.0.0])
+AM_INIT_AUTOMAKE([foreign subdir-objects])
+AC_CONFIG_MACRO_DIRS([m4])
+LT_INIT([shared])
+
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile])
+
+AC_CHECK_HEADERS([stdlib.h stdio.h])
+
+AC_OUTPUT
diff --git a/c_implementation/include/libakfs.h b/c_implementation/include/libakfs.h
new file mode 100644
index 0000000..bc5703c
--- /dev/null
+++ b/c_implementation/include/libakfs.h
@@ -0,0 +1,119 @@
+#ifndef AKFS
+#define AKFS
+
+#include <stdbool.h>
+
+/**
+ * This struct represents a HEX output of the SHA-512 algorithm.
+ *
+ */
+typedef struct {
+ /**
+ * The array below has size of 8, which can store the 128 characters into
+ * 16 digit length variables.
+ *
+ * While 512bits/8bits=64bytes, into converting to characters, we use 2bytes
+ * per one digit, which gives us the 128 characters.
+ *
+ */
+ long unsigned int sum[8];
+} sha512sum;
+
+/**
+ * This struct describes explicitly the structure of a root_hash. It is the root
+ * of a hash merkle tree. Note, that this structure can be used for roots and
+ * branches. Possibly, the name will change to something more generic in the
+ * future.
+ * Another note is that instead of approaching this as left and right, as seen
+ * in other codebases, we do a head-tail naming. That's because of the BASH
+ * implementation that you can find at lib/_ak_fs.
+ *
+ */
+typedef struct {
+ /**
+ * Hash of the thing
+ */
+ sha512sum root;
+ /**
+ * Hash of head
+ */
+ sha512sum head;
+ /**
+ * Hash of tail
+ */
+ sha512sum tail;
+} root_hash;
+
+/**
+ * This is the current structure of an akfs_map. Due to potential short-comings
+ * of it, akfs_map_v4 was introduced. Versions v1 and v2 won't be appearing in
+ * this header file, since they were long abandoned. Version v0, on the other
+ * hand, is what is called now as a root_hash. Refer to it for more.
+ *
+ */
+typedef struct {
+ /**
+ * Original file's hash
+ *
+ */
+ sha512sum oh;
+ /**
+ * Original file's name
+ *
+ */
+ char* filename;
+ /**
+ * Root hash
+ *
+ */
+ sha512sum rh;
+ /**
+ * Should be "level.1.map" at all times
+ *
+ */
+ char* root_name;
+} akfs_map_v3;
+
+/**
+ * This is a proposed structure for akfs_map. It is called after its version.
+ * Previous versions have been mostly abandoned, except v3 which is where v4
+ * was derived from. See akfs_map_v3 for more.
+ *
+ */
+typedef struct {
+ /**
+ * Original file's hash
+ *
+ */
+ sha512sum oh;
+ /**
+ * Original filename's AKFS maphash
+ *
+ */
+ sha512sum fn;
+ /**
+ * Root hash
+ *
+ */
+ sha512sum rh;
+} akfs_map_v4;
+
+//typedef char[64] sha512sum_as_string;
+
+char* ak_fs_return_hash_path(char*);
+
+char* ak_fs_return_hash_dir(char*);
+
+bool ak_fs_verify_input_is_hash(char*);
+
+int ak_fs_create_dir_for_hash(char*);
+
+sha512sum ak_fs_sha512sum_string_to_struct(char*);
+
+void ak_fs_sha512sum_struct_to_string(sha512sum, char*);
+
+int ak_fs_open_map_v3(char*);
+int ak_fs_from_map_v3_to_file(akfs_map_v3);
+
+#endif // AKFS
+
diff --git a/src/include/aklog.h b/c_implementation/include/libaklog.h
index ff396ea..31478a7 100644
--- a/src/include/aklog.h
+++ b/c_implementation/include/libaklog.h
@@ -1,12 +1,20 @@
#ifndef AKLOG
#define AKLOG
+typedef enum {
+ INFO,
+ WARNING,
+ ERROR,
+ EXIT,
+ DEBUG
+} LogMessageType;
+
void ak_log_print_log_line(char* line);
void ak_log_follow();
void ak_log_grep(char* string);
void ak_log_rotate();
int ak_log_write_to_file(char* message);
-void ak_log_message(const char* program, char* type, char* message);
+void ak_log_message(const char* program, LogMessageType lmtype, char* message);
void ak_log_exit(const char* program, char* message);
void ak_log_warning(const char* program, char* message);
void ak_log_debug(const char* program, char* message);
diff --git a/src/include/aklogcatter.h b/c_implementation/include/libaklogcatter.h
index 650ef7c..650ef7c 100644
--- a/src/include/aklogcatter.h
+++ b/c_implementation/include/libaklogcatter.h
diff --git a/c_implementation/include/libaksettings.h b/c_implementation/include/libaksettings.h
new file mode 100644
index 0000000..e95f37d
--- /dev/null
+++ b/c_implementation/include/libaksettings.h
@@ -0,0 +1,25 @@
+#ifndef AK_SETTINGS_H
+#define AK_SETTINGS_H
+
+#include <stdbool.h>
+
+typedef struct {
+ char *key;
+ char *value;
+} AKSetting;
+
+int ak_settings();
+void ak_settings_print_setting(AKSetting);
+int ak_settings_from_file();
+int ak_setting_to_file(AKSetting);
+
+
+const char *ak_settings_get_setting(const char *key);
+bool ak_settings_set_setting(const char *key, const char *value);
+bool ak_settings_save_settings();
+bool ak_settings_load_settings_binary();
+int ak_settings_find_setting(const char *key);
+void ak_settings_free_settings();
+bool ak_settings_save_settings_binary();
+
+#endif // AK_SETTINGS_H
diff --git a/c_implementation/include/libakutils.h b/c_implementation/include/libakutils.h
new file mode 100644
index 0000000..4243b64
--- /dev/null
+++ b/c_implementation/include/libakutils.h
@@ -0,0 +1,24 @@
+#ifndef AK_UTILS_H
+#define AK_UTILS_H
+
+int ak_utils();
+
+typedef long unsigned int UnixSeconds;
+
+/**
+ *
+ * function _ak_datetime_unix();
+ *
+ * function _ak_datetime_unix_nanosecs();
+ *
+ * function _ak_datetime_human();
+ *
+ * function _ak_datetime_human_date_only();
+ *
+ * function _ak_datetime_human_date_only_yesterday();
+ *
+ * function _ak_datetime_unix_to_human();
+ *
+ */
+
+#endif // AK_UTILS_H
diff --git a/src/akfs.c b/c_implementation/src/akfs.c
index c79882a..a71a003 100644
--- a/src/akfs.c
+++ b/c_implementation/src/akfs.c
@@ -3,7 +3,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
-#include <akfs.h>
+#include <libakfs.h>
#include <sys/stat.h>
char* ak_fs_return_hash_path(char* string)
@@ -324,3 +324,26 @@ void ak_fs_sha512sum_struct_to_string(sha512sum hash, char* string)
}
string[128] = '\0';
}
+
+int ak_fs_open_map_v3(char* maphash)
+{
+ if ( ak_fs_verify_input_is_hash(maphash) )
+ {
+ //FILE *fd;
+ //char *mapsdir = "/home/kaotisk/.arching-kaos/akfs/maps/";
+ //strncat(mapsdir, maphash);
+ // printf("%s\n", mapsdir);
+ exit(1);
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+int ak_fs_from_map_v3_to_file(akfs_map_v3 maphash)
+{
+ (void)maphash;
+ return 0;
+}
diff --git a/src/aklog.c b/c_implementation/src/aklog.c
index 10062b0..f6b04e8 100644
--- a/src/aklog.c
+++ b/c_implementation/src/aklog.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include "libaklog.h"
#define AK_DEBUG true
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
@@ -175,7 +176,6 @@ void ak_log_grep(char* message)
exit(1);
}
}
-
printf("The following scripts have entries in the log file.\n");
printf("Select one of those by entering the number of it below and hit enter:\n");
// select x in $(cat $AK_LOGSFILE | cut -d ' ' -f 2 | sort | uniq)
@@ -205,85 +205,83 @@ void ak_log_rotate()
exit(2);
}
-void ak_log_message(char* program, char* type, char* message)
+void ak_log_message(const char* program, LogMessageType lmtype, char* message)
{
time_t ts = time(NULL);
time(&ts);
char* some_string = {0};
+ char* type = {0};
if ( program != NULL )
{
- if ( type != NULL )
+ switch(lmtype)
{
- if ( message != NULL )
- {
- // msg="$(echo -n $*| cut -d ' ' -f 3-)"
- // echo "$TS" "<$1>" "[$2]" "$msg" >> $AK_LOGSFILE
- printf( "%ld <%s> [%s] %s\n", ts, program, type, message); // out to file though
- if ( AK_DEBUG )
- {
- asprintf(&some_string, "%ld <%s> [%s] %s", ts, program, type, message);
- ak_log_print_log_line(some_string);
- ak_log_write_to_file(some_string);
- // fprintf(stderr, "%ld <%s> [%s] %s\n", ts, program, type, message);
- }
- }
- else
- {
- // echo "$TS" "<$1>" "[ERROR]" "No message" >> $AK_LOGSFILE
- printf("%ld <%s> [ERROR] No message\n", ts, program); // out to file
- if ( AK_DEBUG )
- {
- fprintf(stderr, "%ld <%s> [ERROR] No message\n", ts, program);
- }
+ case ERROR:
+ type = "ERROR";
+ break;
+ case INFO:
+ type = "INFO";
+ break;
+ case WARNING:
+ type = "WARNING";
+ break;
+ case EXIT:
+ type = "EXIT";
+ break;
+ case DEBUG:
+ type = "DEBUG";
+ break;
+ default:
+ asprintf(&some_string, "%ld <%s> [ERROR] No message type\n", ts, program);
+ ak_log_write_to_file(some_string);
+ if ( AK_DEBUG ) ak_log_print_log_line(some_string);
exit(1);
- }
+ }
+ if ( message != NULL )
+ {
+ asprintf(&some_string, "%ld <%s> [%s] %s", ts, program, type, message);
+ ak_log_write_to_file(some_string);
+ if ( AK_DEBUG ) ak_log_print_log_line(some_string);
}
else
{
- // echo "$TS" "<$1>" "[ERROR]" "No type and message" >> $AK_LOGSFILE
-
- printf("%ld <%s> [ERROR] No type and message\n", ts, program); // out to file
- if ( AK_DEBUG )
- {
- fprintf(stderr, "%ld <%s> [ERROR] No type and message\n", ts, program);
- }
+ asprintf(&some_string, "%ld <%s> [ERROR] No message\n", ts, program);
+ ak_log_write_to_file(some_string);
+ if ( AK_DEBUG ) ak_log_print_log_line(some_string);
exit(1);
}
}
else
{
// echo "$TS" "<$(basename $0)>" "[ERROR]" "No arguments given" >> $AK_LOGSFILE
- printf("%ld <%s> [ERROR] No arguments given\n", ts, program); // out to file
- if ( AK_DEBUG )
- {
- fprintf(stderr, "%ld <%s> [ERROR] No arguments given\n", ts, program);
- }
+ asprintf(&some_string, "%ld <%s> [ERROR] No arguments given\n", ts, program);
+ ak_log_write_to_file(some_string);
+ if ( AK_DEBUG ) ak_log_print_log_line(some_string);
exit(1);
}
}
-void ak_log_exit(char* program, char* message)
+void ak_log_exit(const char* program, char* message)
{
- ak_log_message(program, "EXIT", message);
+ ak_log_message(program, EXIT, message);
}
-void ak_log_warning(char* program, char* message)
+void ak_log_warning(const char* program, char* message)
{
- ak_log_message(program, "WARNING", message);
+ ak_log_message(program, WARNING, message);
}
-void ak_log_debug(char* program, char* message)
+void ak_log_debug(const char* program, char* message)
{
- ak_log_message(program, "DEBUG", message);
+ ak_log_message(program, DEBUG, message);
}
-void ak_log_error(char* program, char* message)
+void ak_log_error(const char* program, char* message)
{
- ak_log_message(program, "ERROR", message);
+ ak_log_message(program, ERROR, message);
}
-void ak_log_info(char* program, char* message)
+void ak_log_info(const char* program, char* message)
{
- ak_log_message(program, "INFO", message);
+ ak_log_message(program, INFO, message);
}
diff --git a/src/aklogcatter.c b/c_implementation/src/aklogcatter.c
index add6c30..54b1f8c 100644
--- a/src/aklogcatter.c
+++ b/c_implementation/src/aklogcatter.c
@@ -1,6 +1,6 @@
-#include <aklogcatter.h>
+#include <libaklogcatter.h>
#include <stdio.h>
-#include <aklog.h>
+#include <libaklog.h>
#include <stdlib.h>
int ak_logcatter()
diff --git a/c_implementation/src/aksettings.c b/c_implementation/src/aksettings.c
new file mode 100644
index 0000000..470330f
--- /dev/null
+++ b/c_implementation/src/aksettings.c
@@ -0,0 +1,113 @@
+#include <libaksettings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#define MAX_SETTINGS 100
+
+AKSetting settings[MAX_SETTINGS];
+int settings_count = 0;
+
+bool ak_settings_write_string(FILE *file, const char *str) {
+ size_t len = strlen(str) + 1; // Include null terminator
+ if (fwrite(&len, sizeof(size_t), 1, file) != 1) return false;
+ if (fwrite(str, sizeof(char), len, file) != len) return false;
+ return true;
+}
+
+char *ak_settings_read_string(FILE *file) {
+ size_t len;
+ if (fread(&len, sizeof(size_t), 1, file) != 1) return NULL;
+ char *str = malloc(len);
+ if (!str) return NULL;
+ if (fread(str, sizeof(char), len, file) != len) {
+ free(str);
+ return NULL;
+ }
+ return str;
+}
+
+void ak_settings_free_settings() {
+ for (int i = 0; i < settings_count; i++) {
+ free(settings[i].key);
+ free(settings[i].value);
+ }
+ settings_count = 0;
+}
+
+int ak_settings_find_setting(const char *key) {
+ for (int i = 0; i < settings_count; i++) {
+ if (strcmp(settings[i].key, key) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+bool ak_settings_load_settings_binary() {
+ FILE *file = fopen("settings.bin", "rb");
+ if (!file) return false;
+ if (fread(&settings_count, sizeof(int), 1, file) != 1) {
+ fclose(file);
+ return false;
+ }
+ for (int i = 0; i < settings_count; i++) {
+ settings[i].key = ak_settings_read_string(file);
+ settings[i].value = ak_settings_read_string(file);
+ if (!settings[i].key || !settings[i].value) {
+ ak_settings_free_settings();
+ fclose(file);
+ return false;
+ }
+ }
+ fclose(file);
+ return true;
+}
+
+bool ak_settings_save_settings_binary() {
+ FILE *file = fopen("settings.bin", "wb");
+ if (!file) return false;
+ if (fwrite(&settings_count, sizeof(int), 1, file) != 1) {
+ fclose(file);
+ return false;
+ }
+ for (int i = 0; i < settings_count; i++) {
+ if (!ak_settings_write_string(file, settings[i].key)) {
+ fclose(file);
+ return false;
+ }
+ if (!ak_settings_write_string(file, settings[i].value)) {
+ fclose(file);
+ return false;
+ }
+ }
+ fclose(file);
+ return true;
+}
+
+bool ak_settings_set_setting(const char *key, const char *value) {
+ int index = ak_settings_find_setting(key);
+ if (index == -1) {
+ if (settings_count >= MAX_SETTINGS) return false;
+ settings[settings_count].key = strdup(key);
+ settings[settings_count].value = strdup(value);
+ if (!settings[settings_count].key || !settings[settings_count].value) {
+ free(settings[settings_count].key);
+ free(settings[settings_count].value);
+ return false;
+ }
+ settings_count++;
+ } else {
+ char *new_value = strdup(value);
+ if (!new_value) return false;
+ free(settings[index].value);
+ settings[index].value = new_value;
+ }
+ return true;
+}
+
+const char *ak_settings_get_setting(const char *key) {
+ int index = ak_settings_find_setting(key);
+ return (index == -1) ? NULL : settings[index].value;
+}
diff --git a/src/aksettings.c b/c_implementation/src/akutils.c
index 6107a01..d58e0a3 100644
--- a/src/aksettings.c
+++ b/c_implementation/src/akutils.c
@@ -1,7 +1,7 @@
-#include <aksettings.h>
+#include <libakutils.h>
#include <stdio.h>
-int ak_settings()
+int ak_utils()
{
printf("Testing: %s\n", __func__);
return 0;
diff --git a/src/tests/test_akfs.c b/c_implementation/tests/test_akfs.c
index 079c00c..d2b5aec 100644
--- a/src/tests/test_akfs.c
+++ b/c_implementation/tests/test_akfs.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <akfs.h>
+#include <libakfs.h>
void correct_string_correct_length()
{
@@ -173,9 +173,14 @@ void hash_save_to_file()
printf("\tNO PASS :(\n");
}
fclose(fd);
- free(resulted_string);
}
+void test_map_opener()
+{
+ ak_fs_open_map_v3("28bde5fa7aacd8da0ec84b61cf3a69141686906c00f8cff904c9a0b12f5a4cf061da254feb188c32b711b2e1d6a3853d5ac3fb0bcd3564899bae55dd30470392");
+}
+
+
int main(void)
{
// Correct one
@@ -201,5 +206,8 @@ int main(void)
// Tempfile test read-write
hash_save_to_file();
+
+ // Map file opener
+ test_map_opener();
return 0;
}
diff --git a/src/tests/test_akfs_mkdir.c b/c_implementation/tests/test_akfs_mkdir.c
index 2ef86b3..9ac98d1 100644
--- a/src/tests/test_akfs_mkdir.c
+++ b/c_implementation/tests/test_akfs_mkdir.c
@@ -1,5 +1,5 @@
#include <stdio.h>
-#include <akfs.h>
+#include <libakfs.h>
void test_non_hash_string(){
char *path = "tes";
diff --git a/src/tests/test_aklog.c b/c_implementation/tests/test_aklog.c
index dad065f..7e3f6a3 100644
--- a/src/tests/test_aklog.c
+++ b/c_implementation/tests/test_aklog.c
@@ -1,4 +1,4 @@
-#include <aklog.h>
+#include <libaklog.h>
</