aboutsummaryrefslogtreecommitdiff
path: root/c_implementation
diff options
context:
space:
mode:
Diffstat (limited to 'c_implementation')
-rw-r--r--c_implementation/Makefile.am22
-rwxr-xr-xc_implementation/build.sh10
-rwxr-xr-xc_implementation/build_tree/ak_fs_build.sh15
-rwxr-xr-xc_implementation/build_tree/ak_log_build.sh13
-rwxr-xr-xc_implementation/build_tree/ak_logcatter_build.sh7
-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.ac12
-rw-r--r--c_implementation/include/libakfs.h119
-rw-r--r--c_implementation/include/libaklog.h24
-rw-r--r--c_implementation/include/libaklogcatter.h6
-rw-r--r--c_implementation/include/libaksettings.h25
-rw-r--r--c_implementation/include/libakutils.h24
-rw-r--r--c_implementation/src/akfs.c349
-rw-r--r--c_implementation/src/aklog.c287
-rw-r--r--c_implementation/src/aklogcatter.c35
-rw-r--r--c_implementation/src/aksettings.c113
-rw-r--r--c_implementation/src/akutils.c8
-rw-r--r--c_implementation/tests/test_akfs.c213
-rw-r--r--c_implementation/tests/test_akfs_mkdir.c38
-rw-r--r--c_implementation/tests/test_aklog.c72
-rw-r--r--c_implementation/tests/test_aklogcatter.c7
-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
28 files changed, 1587 insertions, 0 deletions
diff --git a/c_implementation/Makefile.am b/c_implementation/Makefile.am
new file mode 100644
index 0000000..87089cb
--- /dev/null
+++ b/c_implementation/Makefile.am
@@ -0,0 +1,22 @@
+ACLOCAL_AMFLAGS = -I m4
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+lib_LTLIBRARIES = libaklog.la libaksettings.la
+libaklog_la_SOURCES = $(top_srcdir)/src/aklog.c
+libaksettings_la_SOURCES = $(top_srcdir)/src/aksettings.c
+include_HEADERS = include/libaklog.h include/libaksettings.h
+
+bin_PROGRAMS = ak
+ak_LDADD = libaklog.la
+ak_SOURCES = src/ak.c
+
+check_PROGRAMS = test_aklog
+test_aklog_SOURCES = ./tests/test_aklog.c
+test_aklog_LDADD = libaklog.la
+
+tests_test_main_CPPFLAGS = -I$(top_srcdir)/include
+
+TESTS = $(check_PROGRAMS)
+
+CLEANFILES = $(TESTS)
+
diff --git a/c_implementation/build.sh b/c_implementation/build.sh
new file mode 100755
index 0000000..183f022
--- /dev/null
+++ b/c_implementation/build.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+if [ ! -d $PWD/lib ]
+then
+ mkdir $PWD/lib
+fi
+
+find build_tree -type f | while read build_script
+do
+ bash ${build_script}
+done
diff --git a/c_implementation/build_tree/ak_fs_build.sh b/c_implementation/build_tree/ak_fs_build.sh
new file mode 100755
index 0000000..11b4fde
--- /dev/null
+++ b/c_implementation/build_tree/ak_fs_build.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+echo "Building 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/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/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/c_implementation/build_tree/ak_log_build.sh b/c_implementation/build_tree/ak_log_build.sh
new file mode 100755
index 0000000..76a4113
--- /dev/null
+++ b/c_implementation/build_tree/ak_log_build.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+echo "Building 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/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/libaklog.so -o tests/test_aklogwrite && \
+echo "Running test_aklogwrite" && \
+time ./tests/test_aklogwrite && \
+rm ./tests/test_aklogwrite
diff --git a/c_implementation/build_tree/ak_logcatter_build.sh b/c_implementation/build_tree/ak_logcatter_build.sh
new file mode 100755
index 0000000..aa321cb
--- /dev/null
+++ b/c_implementation/build_tree/ak_logcatter_build.sh
@@ -0,0 +1,7 @@
+echo "Building 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/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..0cedf54
--- /dev/null
+++ b/c_implementation/configure.ac
@@ -0,0 +1,12 @@
+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_HEADERS([config.h])
+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/c_implementation/include/libaklog.h b/c_implementation/include/libaklog.h
new file mode 100644
index 0000000..31478a7
--- /dev/null
+++ b/c_implementation/include/libaklog.h
@@ -0,0 +1,24 @@
+#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, 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);
+void ak_log_error(const char* program, char* message);
+void ak_log_info(const char* program, char* message);
+
+#endif // AKLOG
diff --git a/c_implementation/include/libaklogcatter.h b/c_implementation/include/libaklogcatter.h
new file mode 100644
index 0000000..650ef7c
--- /dev/null
+++ b/c_implementation/include/libaklogcatter.h
@@ -0,0 +1,6 @@
+#ifndef AK_LOGCATTER_H
+#define AK_LOGCATTER_H
+
+int ak_logcatter();
+
+#endif // AK_LOGCATTER_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/c_implementation/src/akfs.c b/c_implementation/src/akfs.c
new file mode 100644
index 0000000..a71a003
--- /dev/null
+++ b/c_implementation/src/akfs.c
@@ -0,0 +1,349 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libakfs.h>
+#include <sys/stat.h>
+
+char* ak_fs_return_hash_path(char* string)
+{
+ if ( ak_fs_verify_input_is_hash(string) )
+ {
+ unsigned int i = 0;
+ char *result = malloc((128*2)+1);
+ while ( string[i] != '\0' )
+ {
+ result[i*2] = string[i];
+ if ( (i*2) + 1 <= 254 )
+ {
+ result[(i*2)+1] = '/';
+ }
+ else
+ {
+ result[(i*2)+1] = '\0';
+ }
+ ++i;
+ }
+ return result;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+char* ak_fs_return_hash_dir(char* string)
+{
+ if ( ak_fs_verify_input_is_hash(string) )
+ {
+ unsigned int i = 0;
+ char *result = malloc((128*2)+1);
+ while ( string[i] != '\0' )
+ {
+ result[i*2] = string[i];
+ if ( (i*2) + 1 <= 254-2 )
+ {
+ result[(i*2)+1] = '/';
+ }
+ else
+ {
+ result[(i*2)+1] = '\0';
+ }
+ ++i;
+ }
+ return result;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+bool ak_fs_verify_input_is_hash(char* string)
+{
+ unsigned int i = 0;
+ while ( string[i] != '\0' )
+ {
+ if (
+ i < 128 &&
+ !(
+ ( string[i] >= 0x30 ) &&
+ (( string[i] <= 0x39) || ( string[i] >= 0x61 )) &&
+ ( string[i] <= 0x66 )
+ )
+ )
+ {
+ return false;
+ }
+ else {
+ i++;
+ }
+ }
+ if ( i > 128 )
+ {
+ return false;
+ }
+ return true;
+}
+
+int ak_fs_create_dir_for_hash(char* string)
+{
+ /* TODO
+ * Some aspects of this function
+ * 1. We need a "root" place to put our dirs into, this is not specified
+ * anywhere in this code but it is spartially specified in other files
+ * like lib/_ak_fs bash script and the rc/config file we currently source
+ * in $HOME/.bashrc
+ * 2. We might need to "lock" onto some version of glibc and be aware of
+ * other systems that do not use that one.
+ */
+ if ( ak_fs_verify_input_is_hash(string) )
+ {
+ char* dir_path = ak_fs_return_hash_dir(string);
+ // We will need to separate the string so we can create the path one
+ // directory at the time
+ int len = strlen(dir_path);
+ for ( int i = 0; i < len+1; ++i)
+ {
+ if ( dir_path[i] == '/' )
+ {
+ //printf("%c\n", dir_path[i]);
+ //char* test = strndup(dir_path, i);
+ //printf("A: [i:%d] [c:%c] - %s\n", i, dir_path[i], test);
+ continue;
+ }
+ else
+ {
+ char* incremental_dir_path = strndup(dir_path, i+1);
+ // printf("B: [i:%d] [c:%c] - %s\n", i, dir_path[i], test);
+ struct stat sb;
+ if (stat(incremental_dir_path, &sb) == 0 && S_ISDIR(sb.st_mode))
+ {
+ continue;
+ }
+ else
+ {
+ int return_code = mkdir(incremental_dir_path, 0777);
+ if ( return_code == 0 )
+ {
+ continue;
+ }
+ else
+ {
+ // should be unreachable I guess since previous checks
+ // though it could be caused by some other kind of error
+ // like, no permission, or exists but is not a directory
+ // but a file, dev, char, pipe whatever this thing
+ // supports anyway
+ free(incremental_dir_path);
+ free(dir_path);
+ return -3;
+ }
+ }
+ free(incremental_dir_path);
+ }
+ }
+ //printf("%d\n", len);
+ //printf("%s\n", dir_path);
+ //const char *pathname = dir_path;
+ //int ec = mkdir(pathname, 0777);
+ //return ec;
+ free(dir_path);
+ return 0;
+ }
+ else
+ {
+ return -2;
+ }
+}
+
+sha512sum ak_fs_sha512sum_string_to_struct(char* string)
+{
+ sha512sum hash = {0};
+ if ( ak_fs_verify_input_is_hash(string) )
+ {
+ for (size_t l = 0; l < 8; ++l)
+ {
+ hash.sum[l]=0;
+ }
+ unsigned int i = 0;
+ unsigned int j = 0;
+ unsigned int k = 4;
+ while ( string[i] != '\0' )
+ {
+ assert( i < 128 && "Length exceeded limit");
+ if ( i % 16 == 0 ) j = i / 16;
+ switch (string[i])
+ {
+ case 0x30:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x0;
+ break;
+ case 0x31:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x1;
+ break;
+ case 0x32:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x2;
+ break;
+ case 0x33:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x3;
+ break;
+ case 0x34:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x4;
+ break;
+ case 0x35:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x5;
+ break;
+ case 0x36:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x6;
+ break;
+ case 0x37:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x7;
+ break;
+ case 0x38:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x8;
+ break;
+ case 0x39:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0x9;
+ break;
+ case 0x61:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0xa;
+ break;
+ case 0x62:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0xb;
+ break;
+ case 0x63:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0xc;
+ break;
+ case 0x64:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0xd;
+ break;
+ case 0x65:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0xe;
+ break;
+ case 0x66:
+ hash.sum[j] = hash.sum[j] << k;
+ hash.sum[j] += 0xf;
+ break;
+ default:
+ assert(0 && "Character out of range");
+ }
+ i++;
+ }
+ if ( i != 128 )
+ {
+ sha512sum hash0 = {0};
+ return hash0;
+ }
+ return hash;
+ }
+ else
+ {
+ return hash;
+ }
+}
+
+void ak_fs_sha512sum_struct_to_string(sha512sum hash, char* string)
+{
+ int counter = 0;
+ for (size_t i = 0; i < 8; ++i)
+ {
+ for (size_t j = 0; j < 16; ++j)
+ {
+ long unsigned first = hash.sum[i]/0xfffffffffffffff;
+ switch(first){
+ case 0:
+ string[counter] = '0';
+ break;
+ case 1:
+ string[counter] = '1';
+ break;
+ case 2:
+ string[counter] = '2';
+ break;
+ case 3:
+ string[counter] = '3';
+ break;
+ case 4:
+ string[counter] = '4';
+ break;
+ case 5:
+ string[counter] = '5';
+ break;
+ case 6:
+ string[counter] = '6';
+ break;
+ case 7:
+ string[counter] = '7';
+ break;
+ case 8:
+ string[counter] = '8';
+ break;
+ case 9:
+ string[counter] = '9';
+ break;
+ case 0xa:
+ string[counter] = 'a';
+ break;
+ case 0xb:
+ string[counter] = 'b';
+ break;
+ case 0xc:
+ string[counter] = 'c';
+ break;
+ case 0xd:
+ string[counter] = 'd';
+ break;
+ case 0xe:
+ string[counter] = 'e';
+ break;
+ case 0xf:
+ string[counter] = 'f';
+ break;
+ default:
+ assert(0 && "Should be unreachable");
+ }
+ counter++;
+ hash.sum[i] = hash.sum[i] << 4;
+ }
+ }
+ 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/c_implementation/src/aklog.c b/c_implementation/src/aklog.c
new file mode 100644
index 0000000..f6b04e8
--- /dev/null
+++ b/c_implementation/src/aklog.c
@@ -0,0 +1,287 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#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]))
+
+int ak_log_write_to_file(char* message)
+{
+ FILE *fp;
+ fp = fopen("/home/kaotisk/.arching-kaos/logs/log", "ab");
+ if (!fp)
+ {
+ perror("fopen");
+ return EXIT_FAILURE;
+ }
+ fwrite(message, strlen(message),1,fp);
+ fwrite("\n", strlen("\n"),1,fp);
+ fclose(fp);
+ return 0;
+}
+
+void ak_log_print_log_line(char* line)
+{
+ if ( line )
+ {
+ int i = 0;
+ int spaces_found = 0;
+ int last_space = -1;
+ long int l = 1000000000;
+ long int ts = 0;
+ struct tm *timeInfo;
+ char ts_string[16]; // %Y%Y%Y%Y%m%m%d%d_%H%H%M%M%S%S
+ while ( line[i] != '\0' )
+ {
+ if ( line[i] == ' ' ) // && spaces_found < 4)
+ {
+ spaces_found++;
+ if (true) //( spaces_found < 4 )
+ {
+ for ( int k = last_space+1; k < i; k++ )
+ {
+ switch(spaces_found){
+ case 1:
+ // TS
+ while (true)
+ {
+ if ( line[k] == ' ' )
+ {
+ timeInfo = localtime(&ts);
+ strftime(ts_string, sizeof(ts_string), "%Y%m%d_%H%M%S", timeInfo);
+ printf("%s ", ts_string);
+ break;
+ }
+ else
+ {
+ switch(line[k])
+ {
+ case '0':
+ ts = 0*l + ts;
+ break;
+ case '1':
+ ts = 1*l + ts;
+ break;
+ case '2':
+ ts = 2*l + ts;
+ break;
+ case '3':
+ ts = 3*l + ts;
+ break;
+ case '4':
+ ts = 4*l + ts;
+ break;
+ case '5':
+ ts = 5*l + ts;
+ break;
+ case '6':
+ ts = 6*l + ts;
+ break;
+ case '7':
+ ts = 7*l + ts;
+ break;
+ case '8':
+ ts = 8*l + ts;
+ break;
+ case '9':
+ ts = 9*l + ts;
+ break;
+ }
+ l = l/10;
+ }
+ k++;
+ }
+ break;
+ case 2:
+ // PROGRAM
+ printf("\033[1;32m");
+ while (true)
+ {
+ if ( line[k] == ' ' )
+ {
+ break;
+ }
+