diff --git a/include/decrypter.h b/include/decrypter.h index eac014f..c4df689 100644 --- a/include/decrypter.h +++ b/include/decrypter.h @@ -21,6 +21,6 @@ along with this program. If not, see . #include -outputFlags decryptText(char *text, char *keyNew); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED +why2_output_flags why2_decrypt_text(char *text, char *keyNew); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED #endif \ No newline at end of file diff --git a/include/encrypter.h b/include/encrypter.h index b4b39ca..7f86fe7 100644 --- a/include/encrypter.h +++ b/include/encrypter.h @@ -21,6 +21,6 @@ along with this program. If not, see . #include -outputFlags encryptText(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED +why2_output_flags why2_encrypt_text(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED #endif \ No newline at end of file diff --git a/include/flags.h b/include/flags.h index c4a0234..0976b80 100644 --- a/include/flags.h +++ b/include/flags.h @@ -20,70 +20,70 @@ along with this program. If not, see . #define WHY2_FLAGS_H //CONSTS -const enum EXIT_CODES //exit codes you fucking idiot +const enum WHY2_EXIT_CODES //exit codes you fucking idiot { - SUCCESS = 0, //EXIT CODE FOR SUCCESSFUL RUN - INVALID_KEY = 1, //EXIT VALUE FOR INVALID KEY - INVALID_TEXT = 4, //EXIT VALUE FOR INVALID TEXT - DOWNLOAD_FAILED = 2, //EXIT VALUE FOR versions.json DOWNLOAD FAILED - UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED + WHY2_SUCCESS = 0, //EXIT CODE FOR WHY2_SUCCESSFUL RUN + WHY2_INVALID_KEY = 1, //EXIT VALUE FOR INVALID KEY + WHY2_INVALID_TEXT = 4, //EXIT VALUE FOR INVALID TEXT + WHY2_DOWNLOAD_FAILED = 2, //EXIT VALUE FOR versions.json DOWNLOAD FAILED + WHY2_WHY2_UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED }; -#define VERSION "v4.3.2" //VERSION OF CURRENT BUILD > DO NOT TOUCH THIS < -#define VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json -#define VERSIONS_NAME "/tmp/why2-versions.json" //do I have to explain this? +#define WHY2_VERSION "v4.3.2" //WHY2_VERSION OF CURRENT BUILD > DO NOT TOUCH THIS < +#define WHY2_VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json +#define WHY2_VERSIONS_NAME "/tmp/why2-versions.json" //do I have to explain this? -#define UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY) -#define UPDATE_NAME "/tmp/why2-update" // fuck you -#define UPDATE_COMMAND "tmux new-session -d \"cd {DIR} && make install\"" +#define WHY2_UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY) +#define WHY2_UPDATE_NAME "/tmp/why2-update" // fuck you +#define WHY2_UPDATE_COMMAND "tmux new-session -d \"cd {DIR} && make install\"" -#define TEST_TEXT "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" //TEST TEXT FOR ENCRYPTION IN why2-test BINARY +#define WHY2_TEST_TEXT "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" //TEST TEXT FOR ENCRYPTION IN why2-test BINARY -#define TEXT_TO_ENCRYPT "Some text yk" //THIS TEXT WILL BE ENCRYPTED IN why2-app BINARY +#define WHY2_TEXT_TO_ENCRYPT "Some text yk" //THIS TEXT WILL BE ENCRYPTED IN why2-app BINARY -#define CLEAR_SCREEN "\e[1;1H\e[2J" //TEXT FOR UNIX CLEAR SCREEN +#define WHY2_CLEAR_SCREEN "\e[1;1H\e[2J" //TEXT FOR UNIX CLEAR SCREEN -#define CURL_TIMEOUT 3 //if you need comment explaining, what the fuck is timeout, don't change WHY2's code, alright? thx, love ya -#define NOT_FOUND_TRIES 10 //NUMBER OF TRIES FOR DOWNLOADING versions.json +#define WHY2_CURL_TIMEOUT 3 //if you need comment explaining, what the fuck is timeout, don't change WHY2's code, alright? thx, love ya +#define WHY2_NOT_FOUND_TRIES 10 //NUMBER OF TRIES FOR DOWNLOADING versions.json -#define DEPRECATED __attribute__((deprecated)) //SAME COMMENT AS VERSIONS_NAME'S -#define UNUSED __attribute__((unused)) //SAME COMMENT AS DEPRECATED'S +#define WHY2_DEPRECATED __attribute__((deprecated)) //SAME COMMENT AS WHY2_VERSIONS_NAME'S +#define WHY2_UNUSED __attribute__((unused)) //SAME COMMENT AS WHY2_DEPRECATED'S //TYPES typedef char why2_bool; //READ THE NAME OR I WILL FIND YOU AND FUCK YOUR MOTHERFUCKING DOG!!! -typedef int (*encryptionOperation_type_cb)(int, int); //TYPE FOR encryptionOperation CALLBACK +typedef int (*why2_encryption_operation_cb)(int, int); //TYPE FOR encryptionOperation CALLBACK typedef struct { - why2_bool noCheck; //BOOLEAN FOR SKIPPING VERSION CHECK - why2_bool noOutput; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING - why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY VERSION IF OLD IS USED -} inputFlags; + why2_bool noCheck; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK + why2_bool why2_no_output; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING + why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED +} why2_input_flags; typedef struct { char *outputText; //VARIABLE FOR ENCRYPTED/DECRYPTED TEXT char *usedKey; //VARIABLE FOR USED/GENERATED KEY - unsigned long unusedKeySize; //VARIABLE FOR COUNT OF UNUSED CHARACTERS IN KEY + unsigned long unusedKeySize; //VARIABLE FOR COUNT OF WHY2_UNUSED CHARACTERS IN KEY unsigned long repeatedKeySize; //VARIABLE FOR COUNT OF REPEATED CHARACTERS IN KEY (basically reversed unusedKeySize) unsigned long elapsedTime; //VARIABLE FOR ELAPSED TIME IN MICROSECONDS => 1s = 1000000µs - enum EXIT_CODES exitCode; //VARIABLE FOR EXIT CODE -} outputFlags; + enum WHY2_EXIT_CODES exitCode; //VARIABLE FOR EXIT CODE +} why2_output_flags; //NOTE: Variables were moved to 'flags.c' to force y'all using getters //GETTERS -char getEncryptionSeparator(void); -unsigned long getKeyLength(void); -inputFlags getDefaultFlags(void); //THIS GENERATES inputFlags WITH DEFAULT VALUES -inputFlags getFlags(void); //RETURNS USED FLAGS -outputFlags noOutput(enum EXIT_CODES exitCode); //SAME AS getDefaultFlags() BUT FOR outputFlags -encryptionOperation_type_cb getEncryptionOperation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION -why2_bool getFlagsChanged(void); +char why2_get_encryption_separator(void); +unsigned long why2_get_key_length(void); +why2_input_flags why2_get_default_flags(void); //THIS GENERATES why2_input_flags WITH DEFAULT VALUES +why2_input_flags why2_get_flags(void); //RETURNS USED FLAGS +why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode); //SAME AS why2_get_default_flags() BUT FOR why2_output_flags +why2_encryption_operation_cb why2_get_encryption_operation(void); //RETURNS FUNCTION WHICH IS USED FOR ENCRYPTION & DECRYPTION +why2_bool why2_get_flags_changed(void); //SETTERS -void setEncryptionSeparator(char encryptionSeparatorNew); -void setKeyLength(int keyLengthNew); -void setFlags(inputFlags newFlags); //.... whatcha think? -void setEncryptionOperation(encryptionOperation_type_cb newEncryptionOperation); //are you that dumb? +void why2_set_encryption_separator(char encryptionSeparatorNew); +void why2_set_key_length(int keyLengthNew); +void why2_set_flags(why2_input_flags newFlags); //.... whatcha think? +void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation); //are you that dumb? #endif diff --git a/include/logger/flags.h b/include/logger/flags.h index 7564779..e822695 100644 --- a/include/logger/flags.h +++ b/include/logger/flags.h @@ -20,53 +20,53 @@ along with this program. If not, see . #define WHY2_LOGGER_FLAGS_H //CONSTS -const enum LOGGER_EXIT_CODES //exit codes you fucking idiot (2#) +const enum LOGGER_WHY2_EXIT_CODES //exit codes you fucking idiot (2#) { INVALID_FILE = -1 //THIS WILL HAPPEN IF YOU USE TOO MUCH LOGS lol }; -#define WRITE_MESSAGE_1 "Hello from logger-test! 👋" -#define WRITE_MESSAGE_2 "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" -#define WRITE_MESSAGE_3 "ˢᵃʸ ʸᵉˢ ᵗᵒ ᵈʳᵘᵍˢ" +#define WHY2_WRITE_MESSAGE_1 "Hello from logger-test! 👋" +#define WHY2_WRITE_MESSAGE_2 "aAzZ( )!?#\\/śŠ <3|420*;㍿㊓ㅅΔ♛👶🏿" +#define WHY2_WRITE_MESSAGE_3 "ˢᵃʸ ʸᵉˢ ᵗᵒ ᵈʳᵘᵍˢ" -#define WRITE_DIR "./logs" -#define LOG_LATEST "latest.log" +#define WHY2_WRITE_DIR "./logs" +#define WHY2_LOG_LATEST "latest.log" -#define LOG_FORMAT "yyyy-mm-dd_xxx.log" //THE LAST xxx IS FOR BASE-16 NUMBER OF USAGE THAT DAY (SO MAX IS 4095 [FFF] USAGES PER DAY) -#define LOG_FORMAT_START "yyyy-mm-dd" //FIRST PART OF LOG_FORMAT +#define WHY2_LOG_FORMAT "yyyy-mm-dd_xxx.log" //THE LAST xxx IS FOR BASE-16 NUMBER OF USAGE THAT DAY (SO MAX IS 4095 [FFF] USAGES PER DAY) +#define WHY2_LOG_FORMAT_START "yyyy-mm-dd" //FIRST PART OF WHY2_LOG_FORMAT -#define LOG_FORMATTING "%s/%s_%03x.log" //SAME THING AS LOG_FORMAT, BUT USED IN sprintf IN logger.c, NOT AS LENGTH -#define LOG_FORMATTING_START "%04d-%02d-%02d" //FIRST PART OF LOG_FORMATTING +#define WHY2_LOG_FORMATTING "%s/%s_%03x.log" //SAME THING AS WHY2_LOG_FORMAT, BUT USED IN sprintf IN logger.c, NOT AS LENGTH +#define WHY2_LOG_FORMATTING_START "%04d-%02d-%02d" //FIRST PART OF WHY2_LOG_FORMATTING -#define WRITE_FORMAT "[hh:mm:ss]: " //LOG MESSAGE'S PREFIX (THE SPACE AT THE END IS INTENTIONAL) -#define WRITE_FORMATTING "[%02d:%02d:%02d]: %s\n" //guess what +#define WHY2_WRITE_FORMAT "[hh:mm:ss]: " //LOG MESSAGE'S PREFIX (THE SPACE AT THE END IS INTENTIONAL) +#define WHY2_WRITE_FORMATTING "[%02d:%02d:%02d]: %s\n" //guess what -#define LOG_LATEST_FORMATTING "%s/%s" +#define WHY2_LOG_LATEST_FORMATTING "%s/%s" -#define MAX_USAGE 0xfff //LOOK AT LOG_FORMAT +#define WHY2_MAX_USAGE 0xfff //LOOK AT WHY2_LOG_FORMAT //TYPES typedef struct { int file; char *fileName; -} logFile; +} why2_log_file; typedef struct { char *key; -} logFlags; +} why2_log_flags; typedef struct { char **decryptedText; unsigned long length; -} decryptedOutput; +} why2_decrypted_output; //GETTERS -logFlags getLogFlags(void); +why2_log_flags why2_get_log_flags(void); //SETTERS -void setLogFlags(logFlags logFlagsNew); +void why2_set_log_flags(why2_log_flags why2_log_flagsNew); #endif \ No newline at end of file diff --git a/include/logger/logger.h b/include/logger/logger.h index e0f71c7..2c8144e 100644 --- a/include/logger/logger.h +++ b/include/logger/logger.h @@ -21,7 +21,7 @@ along with this program. If not, see . #include -logFile initLogger(char *directoryPath); //CREATES LOGGING FILE IN directoryPath -void writeLog(int loggerFile, char *logMessage); //WRITES logMessage TO loggerFile +why2_log_file why2_init_logger(char *directoryPath); //CREATES LOGGING FILE IN directoryPath +void why2_write_log(int loggerFile, char *logMessage); //WRITES logMessage TO loggerFile #endif \ No newline at end of file diff --git a/include/logger/utils.h b/include/logger/utils.h index cdf5b28..7cc20e8 100644 --- a/include/logger/utils.h +++ b/include/logger/utils.h @@ -21,8 +21,8 @@ along with this program. If not, see . #include -void deallocateLogger(logFile logger); //USE THIS IF YOU WANT TO DEALLOCATE FILE POINTER RETURNED BY logger'S initLogger -void deallocateDecryptedOutput(decryptedOutput output); //DEALLOCATION OF POINTER-TO-POINTER, WHY TF ARE YOU READING THIS -decryptedOutput decryptLogger(logFile logger); //PASS logger AND FLAGS, AND PROGRAM WILL DECRYPT YOUR LOG... WHAT DID YOU EXPECT? +void why2_deallocate_logger(why2_log_file logger); //USE THIS IF YOU WANT TO DEALLOCATE FILE POINTER RETURNED BY logger'S why2_init_logger +void why2_deallocate_decrypted_output(why2_decrypted_output output); //DEALLOCATION OF POINTER-TO-POINTER, WHY TF ARE YOU READING THIS +why2_decrypted_output why2_decrypt_logger(why2_log_file logger); //PASS logger AND FLAGS, AND PROGRAM WILL DECRYPT YOUR LOG... WHAT DID YOU EXPECT? #endif \ No newline at end of file diff --git a/include/misc.h b/include/misc.h index cf601cc..ce36aa0 100644 --- a/include/misc.h +++ b/include/misc.h @@ -23,15 +23,15 @@ along with this program. If not, see . #include -void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION -void generateKey(char *key, int keyLength); //GENERATE ENCRYPTION KEY -void deallocateOutput(outputFlags flags); //DEALLOCATES flags -enum EXIT_CODES checkVersion(void); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED -enum EXIT_CODES checkKey(char *key); //CHECKS IF KEY IS VALID -enum EXIT_CODES checkText(char *text); //CHECKS IF TEXT IS VALID -unsigned long countIntLength(int number); //RETURNS LENGTH OF number -unsigned long countUnusedKeySize(char *text, char *key); //COUNT unusedKeySize -unsigned long countRepeatedKeySize(char *text, char *key); //COUNT repeatedKeySize -unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS +void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION +void why2_generate_key(char *key, int keyLength); //GENERATE ENCRYPTION KEY +void why2_deallocate_output(why2_output_flags flags); //DEALLOCATES flags +enum WHY2_EXIT_CODES why2_check_version(void); //THIS FUNCTION CHECKS IF LATEST WHY2_VERSION OF WHY2 IS USED +enum WHY2_EXIT_CODES why2_check_key(char *key); //CHECKS IF KEY IS VALID +enum WHY2_EXIT_CODES why2_check_text(char *text); //CHECKS IF TEXT IS VALID +unsigned long why2_count_int_length(int number); //RETURNS LENGTH OF number +unsigned long why2_count_unused_key_size(char *text, char *key); //COUNT unusedKeySize +unsigned long why2_count_repeated_key_size(char *text, char *key); //COUNT repeatedKeySize +unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS #endif diff --git a/src/core/app/main.c b/src/core/app/main.c index fb4b4a6..ea69eb9 100644 --- a/src/core/app/main.c +++ b/src/core/app/main.c @@ -23,10 +23,10 @@ along with this program. If not, see . int main(void) { //SET FLAGS - setFlags((inputFlags) {1, 1, 0}); + why2_set_flags((why2_input_flags) {1, 1, 0}); - //RUN ENCRYPTION WITH TEXT_TO_ENCRYPT, GENERATE NEW KEY AND DO NOT CHECK FOR ACTIVE VERSION & PREVENT ANY OUTPUT - outputFlags encryptedText = encryptText(TEXT_TO_ENCRYPT, NULL); + //RUN ENCRYPTION WITH WHY2_TEXT_TO_ENCRYPT, GENERATE NEW KEY AND DO NOT CHECK FOR ACTIVE WHY2_VERSION & PREVENT ANY OUTPUT + why2_output_flags encryptedText = why2_encrypt_text(WHY2_TEXT_TO_ENCRYPT, NULL); //SIMPLE TEXT printf @@ -39,11 +39,11 @@ int main(void) "If you'd like to know more about WHY2 Encryption System, please visit: https://github.com/ENGO150/WHY2/wiki \b\n" "Thank you so much for supporting this project!\n" - , TEXT_TO_ENCRYPT, encryptedText.outputText + , WHY2_TEXT_TO_ENCRYPT, encryptedText.outputText ); //DEALLOCATION - deallocateOutput(encryptedText); + why2_deallocate_output(encryptedText); return 0; } \ No newline at end of file diff --git a/src/core/lib/decrypter.c b/src/core/lib/decrypter.c index 771327d..738e28e 100644 --- a/src/core/lib/decrypter.c +++ b/src/core/lib/decrypter.c @@ -26,7 +26,7 @@ along with this program. If not, see . #include #include -outputFlags decryptText(char *text, char *keyNew) +why2_output_flags why2_decrypt_text(char *text, char *keyNew) { //CHECK VARIABLE unsigned char checkExitCode; @@ -36,26 +36,26 @@ outputFlags decryptText(char *text, char *keyNew) struct timeval finishTime; gettimeofday(&startTime, NULL); - //CHECK FOR ACTIVE VERSION - if ((checkExitCode = checkVersion()) != SUCCESS) + //CHECK FOR ACTIVE WHY2_VERSION + if ((checkExitCode = why2_check_version()) != WHY2_SUCCESS) { - return noOutput(checkExitCode); + return why2_no_output(checkExitCode); } //CHECK FOR INVALID text - if ((checkExitCode = checkText(text)) != SUCCESS) + if ((checkExitCode = why2_check_text(text)) != WHY2_SUCCESS) { - return noOutput(checkExitCode); + return why2_no_output(checkExitCode); } //CHECK FOR INVALID key - if ((checkExitCode = checkKey(keyNew)) != SUCCESS) + if ((checkExitCode = why2_check_key(keyNew)) != WHY2_SUCCESS) { - return noOutput(checkExitCode); + return why2_no_output(checkExitCode); } //REDEFINE keyLength - setKeyLength(strlen(keyNew)); + why2_set_key_length(strlen(keyNew)); //VARIABLES char *returningText; @@ -71,7 +71,7 @@ outputFlags decryptText(char *text, char *keyNew) //GET LENGTH OF returningText AND textKeyChain for (int i = 0; i < (int) strlen(usedText); i++) { - if (usedText[i] == getEncryptionSeparator()) numberBuffer++; + if (usedText[i] == why2_get_encryption_separator()) numberBuffer++; } //SET LENGTH (numberBuffer) @@ -81,7 +81,7 @@ outputFlags decryptText(char *text, char *keyNew) textKeyChainLength = numberBuffer; //LOAD textKeyChain - generateTextKeyChain(key, textKeyChain, numberBuffer); + why2_generate_text_key_chain(key, textKeyChain, numberBuffer); //LOAD encryptedTextKeyChain for (int i = 0; i < textKeyChainLength; i++) @@ -91,7 +91,7 @@ outputFlags decryptText(char *text, char *keyNew) //GET LENGTH OF EACH CHARACTER for (int j = 0; j < (int) strlen(usedText); j++) { - if (usedText[j] == getEncryptionSeparator()) break; + if (usedText[j] == why2_get_encryption_separator()) break; numberBuffer++; } @@ -121,7 +121,7 @@ outputFlags decryptText(char *text, char *keyNew) //DECRYPT TEXT for (int i = 0; i < textKeyChainLength; i++) { - textKeyChain[i] = getEncryptionOperation()(textKeyChain[i], encryptedTextKeyChain[i]); + textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], encryptedTextKeyChain[i]); } //LOAD returningText @@ -134,14 +134,14 @@ outputFlags decryptText(char *text, char *keyNew) gettimeofday(&finishTime, NULL); //LOAD output - outputFlags output = + why2_output_flags output = { returningText, //DECRYPTED TEXT key, //USED KEY - countUnusedKeySize(returningText, key), // NUMBER OF UNUSED CHARS IN KEY - countRepeatedKeySize(returningText, key), //NUMBER OF REPEATED CHARS IN KEY - compareTimeMicro(startTime, finishTime), // ELAPSED TIME - SUCCESS //EXIT CODE + why2_count_unused_key_size(returningText, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY + why2_count_repeated_key_size(returningText, key), //NUMBER OF REPEATED CHARS IN KEY + why2_compare_time_micro(startTime, finishTime), // ELAPSED TIME + WHY2_SUCCESS //EXIT CODE }; //DEALLOCATION diff --git a/src/core/lib/encrypter.c b/src/core/lib/encrypter.c index f336124..7a1661a 100644 --- a/src/core/lib/encrypter.c +++ b/src/core/lib/encrypter.c @@ -26,7 +26,7 @@ along with this program. If not, see . #include #include -outputFlags encryptText(char *text, char *keyNew) +why2_output_flags why2_encrypt_text(char *text, char *keyNew) { //CHECK VARIABLE unsigned char checkExitCode; @@ -36,16 +36,16 @@ outputFlags encryptText(char *text, char *keyNew) struct timeval finishTime; gettimeofday(&startTime, NULL); - //CHECK FOR ACTIVE VERSION - if ((checkExitCode = checkVersion()) != SUCCESS) + //CHECK FOR ACTIVE WHY2_VERSION + if ((checkExitCode = why2_check_version()) != WHY2_SUCCESS) { - return noOutput(checkExitCode); + return why2_no_output(checkExitCode); } //CHECK FOR INVALID text - if ((checkExitCode = checkText(text)) != SUCCESS) + if ((checkExitCode = why2_check_text(text)) != WHY2_SUCCESS) { - return noOutput(checkExitCode); + return why2_no_output(checkExitCode); } //VARIABLES @@ -58,35 +58,35 @@ outputFlags encryptText(char *text, char *keyNew) if (keyNew != NULL) { //CHECK FOR INVALID key - if ((checkExitCode = checkKey(keyNew)) != SUCCESS) + if ((checkExitCode = why2_check_key(keyNew)) != WHY2_SUCCESS) { - return noOutput(checkExitCode); + return why2_no_output(checkExitCode); } key = strdup(keyNew); //REDEFINE keyLength - setKeyLength(strlen(key)); + why2_set_key_length(strlen(key)); } else //LOAD KEY { - key = malloc(getKeyLength() + 1); + key = malloc(why2_get_key_length() + 1); - generateKey(key, getKeyLength()); + why2_generate_key(key, why2_get_key_length()); } //LOAD textKeyChain - generateTextKeyChain(key, textKeyChain, strlen(text)); + why2_generate_text_key_chain(key, textKeyChain, strlen(text)); //ACTUALLY ENCRYPT TEXT for (int i = 0; i < (int) strlen(text); i++) { - textKeyChain[i] = getEncryptionOperation()(textKeyChain[i], (int) text[i]); + textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], (int) text[i]); } //COUNT REQUIRED SIZE FOR returningText for (int i = 0; i < (int) strlen(text); i++) { - numberBuffer += countIntLength(textKeyChain[i]); + numberBuffer += why2_count_int_length(textKeyChain[i]); } //ALLOCATE returningText (WITH THE SEPARATORS) @@ -95,7 +95,7 @@ outputFlags encryptText(char *text, char *keyNew) //LOAD returningText for (int i = 0; i < (int) strlen(text); i++) { - numberBuffer = sizeof(int) * countIntLength(textKeyChain[i]); + numberBuffer = sizeof(int) * why2_count_int_length(textKeyChain[i]); textBuffer = realloc(textBuffer, numberBuffer); @@ -106,7 +106,7 @@ outputFlags encryptText(char *text, char *keyNew) if (i != (int) strlen(text) - 1) { textBuffer = realloc(textBuffer, 2); - sprintf(textBuffer, "%c", getEncryptionSeparator()); + sprintf(textBuffer, "%c", why2_get_encryption_separator()); strcat(returningText, textBuffer); } @@ -116,14 +116,14 @@ outputFlags encryptText(char *text, char *keyNew) gettimeofday(&finishTime, NULL); //LOAD output - outputFlags output = + why2_output_flags output = { returningText, //ENCRYPTED TEXT key, //GENERATED/USED KEY - countUnusedKeySize(text, key), // NUMBER OF UNUSED CHARS IN KEY - countRepeatedKeySize(text, key), //NUMBER OF REPEATED CHARS IN KEY - compareTimeMicro(startTime, finishTime), // ELAPSED TIME - SUCCESS //EXIT CODE + why2_count_unused_key_size(text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY + why2_count_repeated_key_size(text, key), //NUMBER OF REPEATED CHARS IN KEY + why2_compare_time_micro(startTime, finishTime), // ELAPSED TIME + WHY2_SUCCESS //EXIT CODE }; //DEALLOCATION diff --git a/src/core/lib/flags.c b/src/core/lib/flags.c index fdfdca3..1f707f8 100644 --- a/src/core/lib/flags.c +++ b/src/core/lib/flags.c @@ -21,86 +21,86 @@ along with this program. If not, see . #include //CONSTS (this is just local) -#define DEFAULT_FLAGS (inputFlags) { 0, 0, 0 } +#define DEFAULT_FLAGS (why2_input_flags) { 0, 0, 0 } int encryptionOperation(int text, int encryptedText); //VARIABLES -char encryptionSeparator = '.'; //NOPE > DO NOT TOUCH THIS, USE setEncryptionSeparator instead < -unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE setKeyLength instead < -inputFlags flagsAllah = DEFAULT_FLAGS; //IT IS CALLED flagsAllah CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS -encryptionOperation_type_cb encryptionOperation_cb = encryptionOperation; -why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE setFlags +char encryptionSeparator = '.'; //NOPE > DO NOT TOUCH THIS, USE why2_set_encryption_separator instead < +unsigned long keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS, USE why2_set_key_length instead < +why2_input_flags flagsAllah = DEFAULT_FLAGS; //IT IS CALLED flagsAllah CUZ flags CAUSED SOME FUCKING MEMORY PROBLEMS +why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation; +why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags //GETTERS -char getEncryptionSeparator(void) +char why2_get_encryption_separator(void) { return encryptionSeparator; } -unsigned long getKeyLength(void) +unsigned long why2_get_key_length(void) { return keyLength; } -inputFlags getDefaultFlags(void) +why2_input_flags why2_get_default_flags(void) { return DEFAULT_FLAGS; } -inputFlags getFlags(void) +why2_input_flags why2_get_flags(void) { return flagsAllah; } -outputFlags noOutput(enum EXIT_CODES exitCode) +why2_output_flags why2_no_output(enum WHY2_EXIT_CODES exitCode) { char *emptyText = malloc(1); //TEXT emptyText[0] = '\0'; - char *emptyKey = malloc(getKeyLength() + 1); //KEY - for (int i = 0; i < (int) getKeyLength(); i++) + char *emptyKey = malloc(why2_get_key_length() + 1); //KEY + for (int i = 0; i < (int) why2_get_key_length(); i++) { emptyKey[i] = 'x'; } - emptyKey[getKeyLength()] = '\0'; + emptyKey[why2_get_key_length()] = '\0'; - return (outputFlags) { emptyText, emptyKey, 0, 0, 0, exitCode }; + return (why2_output_flags) { emptyText, emptyKey, 0, 0, 0, exitCode }; } -encryptionOperation_type_cb getEncryptionOperation(void) +why2_encryption_operation_cb why2_get_encryption_operation(void) { return encryptionOperation_cb; } -why2_bool getFlagsChanged(void) +why2_bool why2_get_flags_changed(void) { return flagsChanged; } //SETTERS -void setEncryptionSeparator(char encryptionSeparatorNew) +void why2_set_encryption_separator(char encryptionSeparatorNew) { if (encryptionSeparatorNew <= 31) return; encryptionSeparator = encryptionSeparatorNew; } -void setKeyLength(int keyLengthNew) +void why2_set_key_length(int keyLengthNew) { if (keyLengthNew < 1) return; keyLength = keyLengthNew; } -void setFlags(inputFlags newFlags) +void why2_set_flags(why2_input_flags newFlags) { flagsAllah = newFlags; if (!flagsChanged) flagsChanged = 1; } -void setEncryptionOperation(encryptionOperation_type_cb newEncryptionOperation) +void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOperation) { encryptionOperation_cb = newEncryptionOperation; } diff --git a/src/core/lib/test/main.c b/src/core/lib/test/main.c index 19bbe8d..10977d6 100644 --- a/src/core/lib/test/main.c +++ b/src/core/lib/test/main.c @@ -39,7 +39,7 @@ int main(void) FILE *outputStreamBuffer = stdout; //FLAGS - inputFlags flags = + why2_input_flags flags = { 0, //SKIP CHECK 0, //NO OUTPUT @@ -47,37 +47,37 @@ int main(void) }; //SET FLAGS - setFlags(flags); + why2_set_flags(flags); //SET KEY_LENGTH TO 100 - setKeyLength(100); + why2_set_key_length(100); //SET ENCRYPTION_SEPARATOR TO '|' - setEncryptionSeparator('|'); + why2_set_encryption_separator('|'); //SET outputBuffer to NULL outputBuffer[0] = '\0'; //SET encryptionOperation to encryptionOperationTest - setEncryptionOperation(encryptionOperationTest); + why2_set_encryption_operation(encryptionOperationTest); //ENCRYPT - outputFlags encrypted = encryptText(TEST_TEXT, NULL); + why2_output_flags encrypted = why2_encrypt_text(WHY2_TEST_TEXT, NULL); textBuffer = strdup(encrypted.outputText); //GET ENCRYPTED TEXT keyBuffer = strdup(encrypted.usedKey); //GET KEY timeBuffer = encrypted.elapsedTime; //GET TIME 1 //DEALLOCATE BUFFER - deallocateOutput(encrypted); + why2_deallocate_output(encrypted); //DECRYPT - encrypted = decryptText(textBuffer, keyBuffer); + encrypted = why2_decrypt_text(textBuffer, keyBuffer); timeBuffer += encrypted.elapsedTime; //GET TIME 1 //COMPARE DIFFERENCE - if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0) //SUCCESS + if (strcmp(encrypted.outputText, WHY2_TEST_TEXT) == 0 && encrypted.exitCode == 0) //WHY2_SUCCESS { statusBuffer = strdup("successful"); } @@ -107,7 +107,7 @@ int main(void) "REPEATED KEY: \t\"%lu\"\n" "EXIT CODE: \t\"%d\"\n" - , statusBuffer, TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.repeatedKeySize, encrypted.exitCode + , statusBuffer, WHY2_TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.repeatedKeySize, encrypted.exitCode ); //DEALLOCATION @@ -115,7 +115,7 @@ int main(void) free(keyBuffer); free(statusBuffer); free(outputBuffer); - deallocateOutput(encrypted); + why2_deallocate_output(encrypted); return exitCode; } diff --git a/src/core/lib/utils/misc.c b/src/core/lib/utils/misc.c index d6aef8b..6645f3c 100644 --- a/src/core/lib/utils/misc.c +++ b/src/core/lib/utils/misc.c @@ -37,7 +37,7 @@ double multiply_cb(int a, int b) { return a * b; } double subtract_cb(int a, int b) { return a - b; } double sum_cb(int a, int b) { return a + b; } -int unlink_cb(const char *fpath, UNUSED const struct stat *sb, UNUSED int typeflag, UNUSED struct FTW *ftwbuf) +int unlink_cb(const char *fpath, WHY2_UNUSED const struct stat *sb, WHY2_UNUSED int typeflag, WHY2_UNUSED struct FTW *ftwbuf) { int rv = remove(fpath); @@ -87,21 +87,21 @@ char *replaceWord(char *string, char *old, char *new) //CODE FROM: https://www.g return result; } -enum EXIT_CODES checkVersion(void) +enum WHY2_EXIT_CODES why2_check_version(void) { - if (getFlags().noCheck) return SUCCESS; + if (why2_get_flags().noCheck) return WHY2_SUCCESS; //FILE-CHECK VARIABLES int notFoundBuffer = 0; //CURL VARIABLES CURL *curl = curl_easy_init(); - FILE *fileBuffer = fopen(VERSIONS_NAME, "w+"); + FILE *fileBuffer = fopen(WHY2_VERSIONS_NAME, "w+"); //GET versions.json - curl_easy_setopt(curl, CURLOPT_URL, VERSIONS_URL); + curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fileBuffer); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT); //DOWNLOAD versions.json curl_easy_perform(curl); @@ -110,17 +110,17 @@ enum EXIT_CODES checkVersion(void) curl_easy_cleanup(curl); fclose(fileBuffer); - while (access(VERSIONS_NAME, R_OK) != 0) + while (access(WHY2_VERSIONS_NAME, R_OK) != 0) { notFoundBuffer++; - if (notFoundBuffer == NOT_FOUND_TRIES) + if (notFoundBuffer == WHY2_NOT_FOUND_TRIES) { - if (!getFlags().noOutput) fprintf(stderr, "%s'%s' not found! Exiting...\n", CLEAR_SCREEN, VERSIONS_NAME); - return DOWNLOAD_FAILED; + if (!why2_get_flags().why2_no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME); + return WHY2_DOWNLOAD_FAILED; } - if (!getFlags().noOutput) printf("%s'%s' not found (%dx)! Trying again in a second.\n", CLEAR_SCREEN, VERSIONS_NAME, notFoundBuffer); + if (!why2_get_flags().why2_no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME, notFoundBuffer); sleep(1); } @@ -131,7 +131,7 @@ enum EXIT_CODES checkVersion(void) int bufferSize; //COUNT LENGTH OF buffer AND STORE IT IN bufferSize - fileBuffer = fopen(VERSIONS_NAME, "r"); + fileBuffer = fopen(WHY2_VERSIONS_NAME, "r"); fseek(fileBuffer, 0, SEEK_END); bufferSize = ftell(fileBuffer); rewind(fileBuffer); //REWIND fileBuffer (NO SHIT) @@ -147,14 +147,14 @@ enum EXIT_CODES checkVersion(void) //CHECK FOR TEXT IN buffer if (strcmp(buffer, "") == 0) { - if (!getFlags().noOutput) fprintf(stderr, "You probably aren't connected to internet! This release could be unsafe!\n\n"); + if (!why2_get_flags().why2_no_output) fprintf(stderr, "You probably aren't connected to internet! This release could be unsafe!\n\n"); //WAIT FOR 5 SECONDS sleep(5); free(buffer); fclose(fileBuffer); - return SUCCESS; + return WHY2_SUCCESS; } //CLEANUP @@ -164,16 +164,16 @@ enum EXIT_CODES checkVersion(void) parsedJson = json_tokener_parse(buffer); //yes, ik, i could use json_object_from_file, but I need to check for internet somehow json_object_object_get_ex(parsedJson, "active", &active); - if (strcmp(VERSION, json_object_get_string(active)) != 0) + if (strcmp(WHY2_VERSION, json_object_get_string(active)) != 0) { //UPDATE - if (getFlags().update) + if (why2_get_flags().update) { //CHECK FOR ROOT PERMISSIONS if (getuid() != 0) { - if (!getFlags().noOutput) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n"); - return UPDATE_FAILED; + if (!why2_get_flags().why2_no_output) fprintf(stderr, "You need to be root to update!\t[I DO NOT RECOMMEND USING THIS]\n"); + return WHY2_WHY2_UPDATE_FAILED; } //VARIABLES @@ -183,48 +183,48 @@ enum EXIT_CODES checkVersion(void) int installCode; //MESSAGE - if (!getFlags().noOutput) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n"); + if (!why2_get_flags().why2_no_output) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n"); - //CHECK IF WHY2 REPO ISN'T ALREADY FOUND IN 'UPDATE_NAME' - if (access(UPDATE_NAME, F_OK) == 0) + //CHECK IF WHY2 REPO ISN'T ALREADY FOUND IN 'WHY2_UPDATE_NAME' + if (access(WHY2_UPDATE_NAME, F_OK) == 0) { - removeDirectory(UPDATE_NAME); + removeDirectory(WHY2_UPDATE_NAME); } git_libgit2_init(); //START GIT2 - exitCode = git_clone(&repo, UPDATE_URL, UPDATE_NAME, NULL); //CLONE + exitCode = git_clone(&repo, WHY2_UPDATE_URL, WHY2_UPDATE_NAME, NULL); //CLONE git_libgit2_shutdown(); //STOP GIT2 //CHECK FOR ERRORS if (exitCode != 0) { - if (!getFlags().noOutput) fprintf(stderr, "Updating failed! (cloning)\n"); - return UPDATE_FAILED; + if (!why2_get_flags().why2_no_output) fprintf(stderr, "Updating failed! (cloning)\n"); + return WHY2_WHY2_UPDATE_FAILED; } //COUNT installCommand LENGTH & ALLOCATE IT - installCommand = replaceWord(UPDATE_COMMAND, "{DIR}", UPDATE_NAME); + installCommand = replaceWord(WHY2_UPDATE_COMMAND, "{DIR}", WHY2_UPDATE_NAME); installCode = system(installCommand); //INSTALL //REMOVE versions.json - OTHERWISE WILL CAUSE SEGFAULT IN NEXT RUN - remove(VERSIONS_NAME); + remove(WHY2_VERSIONS_NAME); free(installCommand); //CHECK FOR ERRORS if (installCode != 0) { - if (!getFlags().noOutput) fprintf(stderr, "Updating failed! (installing)\n"); - return UPDATE_FAILED; + if (!why2_get_flags().why2_no_output) fprintf(stderr, "Updating failed! (installing)\n"); + return WHY2_WHY2_UPDATE_FAILED; } - goto deallocation; //GREAT SUCCESS! + goto deallocation; //GREAT WHY2_SUCCESS! } - //COUNT VERSIONS BEHIND + //COUNT WHY2_VERSIONS BEHIND int versionsIndex = -1; int versionsBuffer = 0; @@ -235,7 +235,7 @@ enum EXIT_CODES checkVersion(void) for (int i = 0; i < (int) json_object_array_length(deprecated); i++) { //IT'S A MATCH, BABY :D - if (strcmp(json_object_get_string(json_object_array_get_idx(deprecated, i)), VERSION) == 0) + if (strcmp(json_object_get_string(json_object_array_get_idx(deprecated, i)), WHY2_VERSION) == 0) { versionsIndex = i; @@ -243,10 +243,10 @@ enum EXIT_CODES checkVersion(void) } } - //versions.json DOESN'T CONTAIN VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT) + //versions.json DOESN'T CONTAIN WHY2_VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT) if (versionsIndex == -1) { - if (!getFlags().noOutput) printf("Version %s not found! Check your flags.\n\n", VERSION); + if (!why2_get_flags().why2_no_output) printf("Version %s not found! Check your flags.\n\n", WHY2_VERSION); goto deallocation; } @@ -254,7 +254,7 @@ enum EXIT_CODES checkVersion(void) //COUNT versionsBuffer versionsBuffer = json_object_array_length(deprecated) - versionsIndex; - if (!getFlags().noOutput) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versionsBuffer, VERSION, json_object_get_string(active)); + if (!why2_get_flags().why2_no_output) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versionsBuffer, WHY2_VERSION, json_object_get_string(active)); //WAIT FOR 5 SECONDS sleep(5); @@ -266,10 +266,10 @@ enum EXIT_CODES checkVersion(void) json_object_put(parsedJson); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT free(buffer); - return SUCCESS; + return WHY2_SUCCESS; } -void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize) +void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize) { int numberBuffer; int numberBuffer2; @@ -279,13 +279,13 @@ void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize) { numberBuffer = i; - //CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT UNUSED LENGTH - while (numberBuffer >= (int) getKeyLength()) + //CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT WHY2_UNUSED LENGTH + while (numberBuffer >= (int) why2_get_key_length()) { - numberBuffer -= getKeyLength(); + numberBuffer -= why2_get_key_length(); } - numberBuffer2 = getKeyLength() - (numberBuffer + (i < textKeyChainSize)); + numberBuffer2 = why2_get_key_length() - (numberBuffer + (i < textKeyChainSize)); //FILL textKeyChain if ((numberBuffer + 1) % 3 == 0) @@ -305,13 +305,13 @@ void generateTextKeyChain(char *key, int *textKeyChain, int textKeyChainSize) } } -void deallocateOutput(outputFlags flags) +void why2_deallocate_output(why2_output_flags flags) { free(flags.outputText); free(flags.usedKey); flags.elapsedTime = 0; - flags.exitCode = SUCCESS; + flags.exitCode = WHY2_SUCCESS; flags.repeatedKeySize = 0; flags.unusedKeySize = 0; @@ -319,29 +319,29 @@ void deallocateOutput(outputFlags flags) flags.usedKey = NULL; } -enum EXIT_CODES checkKey(char *key) +enum WHY2_EXIT_CODES why2_check_key(char *key) { - if (strlen(key) < getKeyLength()) + if (strlen(key) < why2_get_key_length()) { - if (!getFlags().noOutput) fprintf(stderr, "Key must be at least %lu characters long!\n", getKeyLength()); - return INVALID_KEY; + if (!why2_get_flags().why2_no_output) fprintf(stderr, "Key must be at least %lu characters long!\n", why2_get_key_length()); + return WHY2_INVALID_KEY; } - return SUCCESS; + return WHY2_SUCCESS; } -enum EXIT_CODES checkText(char *text) +enum WHY2_EXIT_CODES why2_check_text(char *text) { if (strcmp(text, "") == 0) { - if (!getFlags().noOutput) fprintf(stderr, "No text to encrypt!\n"); - return INVALID_TEXT; + if (!why2_get_flags().why2_no_output) fprintf(stderr, "No text to encrypt!\n"); + return WHY2_INVALID_TEXT; } - return SUCCESS; + return WHY2_SUCCESS; } -unsigned long countIntLength(int number) +unsigned long why2_count_int_length(int number) { int returning = 1; int buffer = 10; @@ -363,7 +363,7 @@ unsigned long countIntLength(int number) return returning; } -unsigned long countUnusedKeySize(char *text, char *key) +unsigned long why2_count_unused_key_size(char *text, char *key) { unsigned long returning = 0; @@ -375,7 +375,7 @@ unsigned long countUnusedKeySize(char *text, char *key) return returning; } -unsigned long countRepeatedKeySize(char *text, char *key) +unsigned long why2_count_repeated_key_size(char *text, char *key) { unsigned long returning = 0; @@ -387,12 +387,12 @@ unsigned long countRepeatedKeySize(char *text, char *key) return returning; } -unsigned long compareTimeMicro(struct timeval startTime, struct timeval finishTime) +unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime) { return (finishTime.tv_sec - startTime.tv_sec) * 1000000 + finishTime.tv_usec - startTime.tv_usec; } -void generateKey(char *key, int keyLength) +void why2_generate_key(char *key, int keyLength) { int numberBuffer; diff --git a/src/logger/lib/flags.c b/src/logger/lib/flags.c index d1eaff2..5c8696a 100644 --- a/src/logger/lib/flags.c +++ b/src/logger/lib/flags.c @@ -21,16 +21,16 @@ along with this program. If not, see . #include //VARIABLES -logFlags flags = { NULL }; +why2_log_flags flags = { NULL }; //GETTERS -logFlags getLogFlags(void) +why2_log_flags why2_get_log_flags(void) { return flags; } //SETTERS -void setLogFlags(logFlags logFlagsNew) +void why2_set_log_flags(why2_log_flags why2_log_flagsNew) { - flags = logFlagsNew; + flags = why2_log_flagsNew; } \ No newline at end of file diff --git a/src/logger/lib/logger.c b/src/logger/lib/logger.c index c675d9c..9b921d9 100644 --- a/src/logger/lib/logger.c +++ b/src/logger/lib/logger.c @@ -32,7 +32,7 @@ along with this program. If not, see . #include #include -logFile initLogger(char *directoryPath) +why2_log_file why2_init_logger(char *directoryPath) { //VARIABLES struct stat st; @@ -41,13 +41,13 @@ logFile initLogger(char *directoryPath) struct tm tm = *localtime(&timeL); int buffer = 1; int file; - char *filePath = malloc(strlen(directoryPath) + 1 + strlen(LOG_FORMAT) + 1); - char *dateBuffer = malloc(strlen(LOG_FORMAT_START) + 1); - char *latestBuffer = malloc(strlen(WRITE_DIR) + strlen(LOG_LATEST) + 2); + char *filePath = malloc(strlen(directoryPath) + 1 + strlen(WHY2_LOG_FORMAT) + 1); + char *dateBuffer = malloc(strlen(WHY2_LOG_FORMAT_START) + 1); + char *latestBuffer = malloc(strlen(WHY2_WRITE_DIR) + strlen(WHY2_LOG_LATEST) + 2); char *latestFilePath = NULL; DIR *dir; - sprintf(dateBuffer, LOG_FORMATTING_START, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + sprintf(dateBuffer, WHY2_LOG_FORMATTING_START, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); //CREATE directoryPath DIRECTORY IF IT DOESN'T EXISTS ALREADY if (stat(directoryPath, &st) == -1) @@ -65,24 +65,24 @@ logFile initLogger(char *directoryPath) } } - if (buffer > MAX_USAGE) //MAX_USAGE WAS REACHED + if (buffer > WHY2_MAX_USAGE) //WHY2_MAX_USAGE WAS REACHED { file = INVALID_FILE; goto deallocation; } - sprintf(filePath, LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME + sprintf(filePath, WHY2_LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME file = open(filePath, O_RDWR | O_APPEND | O_CREAT, 0644); //CREATE LOG FILE //CREATE SYMLINK - sprintf(latestBuffer, LOG_LATEST_FORMATTING, WRITE_DIR, LOG_LATEST); //GENERATE LATEST.log PATH + sprintf(latestBuffer, WHY2_LOG_LATEST_FORMATTING, WHY2_WRITE_DIR, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH latestFilePath = strdup(filePath); if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS - (void) (symlink(latestFilePath + (strlen(WRITE_DIR) + 1), latestBuffer) + 1); //TODO: Try to create some function for processing exit value //CREATE + (void) (symlink(latestFilePath + (strlen(WHY2_WRITE_DIR) + 1), latestBuffer) + 1); //TODO: Try to create some function for processing exit value //CREATE deallocation: @@ -92,14 +92,14 @@ logFile initLogger(char *directoryPath) free(latestFilePath); closedir(dir); - return (logFile) + return (why2_log_file) { file, filePath }; } -void writeLog(int loggerFile, char *logMessage) +void why2_write_log(int loggerFile, char *logMessage) { //CHECK IF loggerFile IS CREATED if (loggerFile == INVALID_FILE) @@ -119,28 +119,28 @@ void writeLog(int loggerFile, char *logMessage) char *message = NULL; //FINAL MESSAGE time_t timeL = time(NULL); struct tm tm = *localtime(&timeL); - logFlags flags = getLogFlags(); + why2_log_flags flags = why2_get_log_flags(); //SET ENCRYPTER FLAGS - if (!getFlagsChanged()) setFlags((inputFlags) { 0, 1, 0 }); + if (!why2_get_flags_changed()) why2_set_flags((why2_input_flags) { 0, 1, 0 }); if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED { - outputFlags encrypted = encryptText(logMessageUsed, flags.key); //ENCRYPT + why2_output_flags encrypted = why2_encrypt_text(logMessageUsed, flags.key); //ENCRYPT message = strdup(encrypted.outputText); //COPY //DEALLOCATION - deallocateOutput(encrypted); + why2_deallocate_output(encrypted); free(logMessageUsed); //I COULD DO THIS SMART SOMEHOW, BUT I AM TOO LAZY FOR THAT SHIT } else //FUCK ENCRYPTION, LET'S DO IT; WHY WOULD WE EVEN USE WHY2-CORE? HUH? { message = logMessageUsed; } - buffer = malloc(strlen(WRITE_FORMAT) + strlen(message) + 2); //ALLOCATE + buffer = malloc(strlen(WHY2_WRITE_FORMAT) + strlen(message) + 2); //ALLOCATE - sprintf(buffer, WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, message); //LOAD MESSAGE + sprintf(buffer, WHY2_WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, message); //LOAD MESSAGE (void) (write(loggerFile, buffer, strlen(buffer)) + 1); //TODO: Try to create some function for processing exit value diff --git a/src/logger/lib/test/main.c b/src/logger/lib/test/main.c index f763bce..c480fac 100644 --- a/src/logger/lib/test/main.c +++ b/src/logger/lib/test/main.c @@ -25,36 +25,36 @@ along with this program. If not, see . int main(void) { //VARIABLES - logFile logger = initLogger(WRITE_DIR); //INITIALIZE LOGGER FILE - char *usedKey = malloc(getKeyLength() + 1); - decryptedOutput decrypted; + why2_log_file logger = why2_init_logger(WHY2_WRITE_DIR); //INITIALIZE LOGGER FILE + char *usedKey = malloc(why2_get_key_length() + 1); + why2_decrypted_output decrypted; int exitCode = 0; //GENERATE KEY - generateKey(usedKey, getKeyLength()); + why2_generate_key(usedKey, why2_get_key_length()); //FLAGS - logFlags flags = + why2_log_flags flags = { usedKey }; //SET FLAGS - setLogFlags(flags); + why2_set_log_flags(flags); //WRITE - writeLog(logger.file, WRITE_MESSAGE_1); - writeLog(logger.file, WRITE_MESSAGE_2); - writeLog(logger.file, WRITE_MESSAGE_3); + why2_write_log(logger.file, WHY2_WRITE_MESSAGE_1); + why2_write_log(logger.file, WHY2_WRITE_MESSAGE_2); + why2_write_log(logger.file, WHY2_WRITE_MESSAGE_3); - decrypted = decryptLogger(logger); //DECRYPT + decrypted = why2_decrypt_logger(logger); //DECRYPT //COMPARE OUTPUT - if //SUCCESS //TODO: Make this smart somehow + if //WHY2_SUCCESS //TODO: Make this smart somehow ( - strcmp(decrypted.decryptedText[0], WRITE_MESSAGE_1) == 0 && - strcmp(decrypted.decryptedText[1], WRITE_MESSAGE_2) == 0 && - strcmp(decrypted.decryptedText[2], WRITE_MESSAGE_3) == 0 + strcmp(decrypted.decryptedText[0], WHY2_WRITE_MESSAGE_1) == 0 && + strcmp(decrypted.decryptedText[1], WHY2_WRITE_MESSAGE_2) == 0 && + strcmp(decrypted.decryptedText[2], WHY2_WRITE_MESSAGE_3) == 0 ) { printf @@ -75,8 +75,8 @@ int main(void) //DEALLOCATION free(usedKey); - deallocateLogger(logger); - deallocateDecryptedOutput(decrypted); + why2_deallocate_logger(logger); + why2_deallocate_decrypted_output(decrypted); return exitCode; } \ No newline at end of file diff --git a/src/logger/lib/utils.c b/src/logger/lib/utils.c index 4717905..b5aa31c 100644 --- a/src/logger/lib/utils.c +++ b/src/logger/lib/utils.c @@ -29,7 +29,7 @@ along with this program. If not, see . #include -void deallocateLogger(logFile logger) +void why2_deallocate_logger(why2_log_file logger) { close(logger.file); free(logger.fileName); @@ -38,7 +38,7 @@ void deallocateLogger(logFile logger) logger.file = INVALID_FILE; } -void deallocateDecryptedOutput(decryptedOutput output) +void why2_deallocate_decrypted_output(why2_decrypted_output output) { for (unsigned long i = 0; i < output.length; i++) { @@ -49,10 +49,10 @@ void deallocateDecryptedOutput(decryptedOutput output) free(output.decryptedText); } -decryptedOutput decryptLogger(logFile logger) +why2_decrypted_output why2_decrypt_logger(why2_log_file logger) { FILE *file = fdopen(logger.file, "r"); - outputFlags outputBuffer; + why2_output_flags outputBuffer; char *rawContent; char **content; char **contentDecrypted; @@ -85,11 +85,11 @@ decryptedOutput decryptLogger(logFile logger) { if (rawContent[i] == '\n') //END OF ONE LINE { - content[contentIndexBuffer] = calloc((i - (startingAtBuffer + strlen(WRITE_FORMAT)) + 2), sizeof(char)); //ALLOCATE ELEMENT + content[contentIndexBuffer] = calloc((i - (startingAtBuffer + strlen(WHY2_WRITE_FORMAT)) + 2), sizeof(char)); //ALLOCATE ELEMENT - for (int j = startingAtBuffer + strlen(WRITE_FORMAT); j <= i; j++) //LOAD CONTENT OF EACH LINE + for (int j = startingAtBuffer + strlen(WHY2_WRITE_FORMAT); j <= i; j++) //LOAD CONTENT OF EACH LINE { - content[contentIndexBuffer][j - (startingAtBuffer + strlen(WRITE_FORMAT))] = rawContent[j]; //SET + content[contentIndexBuffer][j - (startingAtBuffer + strlen(WHY2_WRITE_FORMAT))] = rawContent[j]; //SET } contentIndexBuffer++; @@ -99,19 +99,19 @@ decryptedOutput decryptLogger(logFile logger) for (int i = 0; i < lines; i++) //DECRYPT content { - outputBuffer = decryptText(content[i], getLogFlags().key); //DECRYPT + outputBuffer = why2_decrypt_text(content[i], why2_get_log_flags().key); //DECRYPT contentDecrypted[i] = strdup(outputBuffer.outputText); //COPY - deallocateOutput(outputBuffer); //DEALLOCATE outputBuffer + why2_deallocate_output(outputBuffer); //DEALLOCATE outputBuffer } //DEALLOCATION free(rawContent); fclose(file); - deallocateDecryptedOutput((decryptedOutput) { content, lines }); //fuck the system lmao + why2_deallocate_decrypted_output((why2_decrypted_output) { content, lines }); //fuck the system lmao - return (decryptedOutput) + return (why2_decrypted_output) { contentDecrypted, lines