Compare commits

...

544 Commits

Author SHA1 Message Date
3fa15f5ebb
changed ascii range 2024-08-31 16:25:36 +02:00
37a615cb03
got rid of the dumbass goto in read_socket_raw
and possibly created 10 new problems :))
2024-08-31 16:22:34 +02:00
981dec55db
moved is_ascii to separate fn 2024-08-31 16:11:58 +02:00
f7982d4d4a
moved removing non-ascii chars to fn 2024-08-31 16:01:04 +02:00
a9fd0596e5
creating user config on server startup
if user_pick_username is set to true
2024-08-31 14:44:08 +02:00
ada457c824
created macro for server-user config file 2024-08-31 13:20:44 +02:00
48208d0991
fixed double memory leak in init_config fn 2024-08-31 13:02:32 +02:00
b385187d39
added the why2_toml_contains fn to config header 2024-08-31 12:46:12 +02:00
446727b87c
created rust fn for checking if toml contains key 2024-08-31 12:44:15 +02:00
7be5d6ff32
added the why2_toml_write fn to config header 2024-08-31 12:36:52 +02:00
690d979124
created rust fn for writing into toml 2024-08-31 12:36:36 +02:00
f539a4bd71
displaying welcome message on client 2024-08-30 15:06:04 +02:00
329c3c9cd2
added missing why2_directory call to why2_check_version 2024-08-30 15:01:27 +02:00
c28765a4c8
sending server_name in welcome packet 2024-08-30 14:51:27 +02:00
875a1b8ac2
removed useless json syntax checks
its useless since I added check to read_socket_raw
2024-08-30 14:46:45 +02:00
184e71c899
added server_name to server config 2024-08-30 14:40:28 +02:00
972619bafa
fixed server-side pm buffer overflow 2024-08-30 14:31:14 +02:00
17f1329325
removed unused debug stuff 2024-08-30 14:30:55 +02:00
9fd9a4b233
resolving self-pm at client-side :))
haha def no easteregg
2024-08-30 14:12:15 +02:00
809d40ab2e
not sending two packets on self-pm 2024-08-30 13:57:26 +02:00
8bd3df1ae1
added json format validation to read_socket_raw 2024-08-30 13:41:01 +02:00
3fc339a9fb
fully implemented new WHY2_CONFIG_DIR
i moved it to user folder cause it causes permission problems on multi-user machine.
2024-08-30 00:54:17 +02:00
8ef39ada5f
changed WHY2_VERSIONS_NAME 2024-08-30 00:49:45 +02:00
e802f5f483
moved why2_dir from init_config to why2_directory fn 2024-08-30 00:47:52 +02:00
db1d487a2e
moved WHY2_CONFIG_DIR to core-flags 2024-08-30 00:44:38 +02:00
04d411e42a
declared why2_dir fn 2024-08-30 00:42:40 +02:00
ca97b45059
solved infinite loop in read_socket_raw
by the worst possible solution but yeahhh
2024-08-30 00:31:59 +02:00
d12936d1d0
showing pm to both users 2024-08-30 00:23:49 +02:00
2e5e9682a3
decoding pm from end-user 2024-08-30 00:21:59 +02:00
8fcddab726
sending both author and recipient in pm 2024-08-30 00:21:35 +02:00
2d5a18d667
added infinite loop todo
i mean yk, it works but its shit
2024-08-29 23:35:46 +02:00
af233c44ef
sending pm back to end user on server-side 2024-08-28 21:53:19 +02:00
2cc3cd0b78
sending pm back to end user on server-side 2024-08-28 21:52:15 +02:00
3314a82b3a
sending pm to server 2024-08-28 21:24:32 +02:00
456b523012
created WHY2_CHAT_CODE_PM_SERVER code 2024-08-28 14:00:24 +02:00
290ad5c101
moved invalid command/stuff into fn 2024-08-28 13:48:45 +02:00
854e8399fb
trimming string on command fn 2024-08-28 13:48:18 +02:00
7647be3daf
starting IDs from 1 instead of 0
atoi returns 0 in failure, meaning all typos would send PMs to first user
2024-08-28 13:38:17 +02:00
963e75da51
clearing arg on command 2024-08-28 13:21:33 +02:00
66ceb25a89
comment typo fix 2024-08-28 12:59:43 +02:00
0dfd0218e1
added version and pm cmd to help 2024-08-28 12:59:09 +02:00
64773d1f30
implemented version cmd receive half on client-side 2024-08-28 12:45:48 +02:00
41bbfc2b18
reverted the demented why2_get_version 2024-08-28 12:44:33 +02:00
6adf4a391a
removed stupid get_version
im so fucking dumb... i was sending latest why2 verison instead of current
2024-08-28 12:40:30 +02:00
1735da3807
moved why2_get_version string extraction to get_version 2024-08-28 12:21:59 +02:00
ef235e48f7
created server-side code for version command
sending the version back to client
2024-08-28 12:13:59 +02:00
e30e2dea59
created WHY2_CHAT_CODE_VERSION_SERVER code 2024-08-28 12:07:32 +02:00
e5e6460908
changed comment of get_version 2024-08-28 11:58:47 +02:00
debf90e5d2
implemented why2_get_version in why2_check_version 2024-08-28 11:55:29 +02:00
b92ed3d6a8
declared why2_get_version 2024-08-28 11:48:52 +02:00
f20550dec6
removed chat why2_check_version error todo
lol i def have clue why it works now
2024-08-28 11:46:51 +02:00
a4ec91979e
implemented send part of version cmd on client-side 2024-08-28 11:43:50 +02:00
de4b6a39bf
being correct with user pronouns 2024-08-28 11:42:13 +02:00
a5b6364c26
checking version on chat client&server startup 2024-08-28 11:39:01 +02:00
54b4ebe3e6
created version cmd and code
also added missing comments to codes
2024-08-28 11:35:09 +02:00
5442104f35
added list cmd to help 2024-08-28 11:24:13 +02:00
e18ce453be
comment typo fix 2024-08-28 11:21:08 +02:00
59ae168b15
added so pretty way of getting dynamic size of received msg
god damn it, its awesome. Also, I should get rid of the goto in there, that's stupid lol. Gonna do it tmrw ig
2024-08-27 22:42:45 +02:00
aad627b77a
created PM code 2024-04-28 15:25:43 +02:00
d539654cc3
handling LIST code sent back from server 2024-04-28 12:38:34 +02:00
e50184ad66
sedning one separator more on LIST code 2024-04-28 12:37:24 +02:00
bc14effeee
responding to LIST code from client
oh dear satan, this is possibly the worst code I have ever written. Please, if anyone has any idea how to handle strings in C in better ways, let me know.
2024-04-28 11:50:59 +02:00
cd80a640af
created LIST code but from s->c 2024-04-28 11:49:51 +02:00
c37538aa75
defined why2_list_get_size
not sure if this is correct lol

EDIT: It didn't work. I fixed it now lmao
2024-04-27 12:26:56 +02:00
c4ddb6888a
declared why2_list_get_size fn 2024-04-27 12:18:07 +02:00
97ba473143
removed INVALID_COMMAND code
it was unused atp
2024-04-27 12:01:49 +02:00
cfa9f7bcca
implemented WHY2_CHAT_COMMAND_PREFIX on server-side 2024-04-27 11:58:01 +02:00
4134f9d1b3
implemented LIST command in client
not in server yet haha
2024-04-27 11:49:00 +02:00
1b4401f944
created WHY2_CHAT_COMMAND_LIST macro 2024-04-27 11:47:04 +02:00
37b1a3a82d
changed code_998 to CODE_LIST 2024-04-27 11:43:53 +02:00
0150414d1b
optimized client command checking 2024-04-27 11:42:15 +02:00
26c5b4d831
implemented the command handler 2024-04-27 11:33:00 +02:00
e9b439884f
created command handler in client 2024-04-27 11:32:52 +02:00
f325b928eb
trimming client input text 2024-04-25 21:15:59 +02:00
f07a5fe40f
moved trim_string to header file 2024-04-25 20:52:09 +02:00
e6c570c2c7
prepared trim_string for non-why2-allocated strings 2024-04-20 11:32:18 +02:00
65135ac961
created why2_allocated fn
checks for why2-mem allocation
2024-04-20 11:22:09 +02:00
19ccc45e0a
created pm code 2024-04-19 20:09:23 +02:00
07a4eecd4e
removed the stupid exit command sending
using codes instead
2024-04-19 20:03:20 +02:00
d451030ad0
handling sigint signal
i'm really trying alex, i am

wicked game
2024-04-19 16:32:44 +02:00
e023207261
added help command 2024-04-19 16:08:54 +02:00
1fc78a2a30
sending server exit_cmd with the initial welcome message 2024-04-17 18:04:45 +02:00
c98184f1f5
created exit_cmd getter & setter 2024-04-17 18:03:40 +02:00
b2c945fe6d
implemented the exit_cmd macro 2024-04-17 17:45:21 +02:00
b2ca56e927
created WHY2_CHAT_COMMAND_EXIT macro
also the prefix
2024-04-17 17:43:25 +02:00
99c76285a2
added ID to connection node 2024-04-17 17:25:55 +02:00
f1fd7c07ea
fixed linked list linkage problems
First of all, is linkage even a word? :D Second thing, I am so fucking stupid...
2024-04-17 17:22:44 +02:00
586df77ff4
revert "added configure script source todo"
reverts commit abd8645ab06374a345f1698c313e3c6bfc363ed7.

turns out it breaks workflows
2024-04-13 17:19:07 +02:00
22e03ca06e
fixed base bug in exp_mod fn 2024-04-13 14:20:52 +02:00
6227b8eb0a
changed WHY2_CHAT_RSA_EXPONENT base to 62
so now it isn't 65537 but H33
2024-04-13 14:20:26 +02:00
d9483f02ca
fixed rsa crypto input strings & output base 2024-04-13 13:45:40 +02:00
9cf062565a
created why2_chat_rsa_pri_decrypt 2024-04-13 13:40:26 +02:00
2a9df2a4b9
moved why2_chat_rsa_pub_encrypt body into exp_mod
so in next commit, which will be decryption, I won't kms
2024-04-13 13:38:14 +02:00
b74995bbab
changed WHY2_CHAT_RSA_EXPONENT datatype to string 2024-04-13 13:37:06 +02:00
6487ea8b85
defined why2_chat_rsa_pub_encrypt
pog
2024-04-13 13:30:52 +02:00
ee3f319dd7
implemented why2_chat_deallocate_keys in client 2024-04-13 13:17:03 +02:00
62d2f10e65
declared why2_chat_rsa_pub_encrypt 2024-04-13 13:15:26 +02:00
5bd948c8a0
switched fopen for why2_fopen in crypto
whoopsie
2024-04-13 13:09:54 +02:00
60b437d4e8
implemented why2 crypto getters
bit fucked the file
2024-04-13 13:08:44 +02:00
8f3af8c7d1
defined why2_get_chat* rsa stuff fns 2024-04-13 12:32:43 +02:00
bb8436badd
added body for why2_chat_deallocate_keys 2024-04-13 12:32:19 +02:00
2755472534
declared why2_get_chat* rsa stuff fns 2024-04-13 12:28:50 +02:00
2f4c73ce09
created why2_chat_deallocate_keys fn 2024-04-13 12:26:47 +02:00
ef1f9bbf38
renamed why2_chat_generate_keys to why2_chat_init_keys
I think the name is much more self-explanatory now
2024-04-13 12:24:19 +02:00
abd8645ab0
added configure script source todo 2024-04-13 12:19:32 +02:00
274a3e1772
revert "sending ssqc on every message loop end"
this reverts commit b14c8de7105a9f570a227ce7f8608103b205eca9

it seems that I created the check for some reason
2024-02-26 15:19:41 +01:00
850ab11272
using latest toml version in rust module 2024-02-25 20:54:17 +01:00
4d6b29e4c6
implemented max_message_length in message loop 2024-02-25 20:34:18 +01:00
13d4e2f480
created max_message_length in server cfg 2024-02-25 20:25:38 +01:00
b14c8de710
sending ssqc on every message loop end 2024-02-25 14:23:53 +01:00
22282623af
implemented trim_string in message loop 2024-02-25 13:16:12 +01:00
157d56ac57
not disconnecting user on null message 2024-02-25 13:15:54 +01:00
47fd5f01b6
created trim_string fn 2024-02-25 13:15:29 +01:00
a141065189
addded null check to why2_deallocate 2024-02-25 12:25:29 +01:00
0abd38e877
fixed byte format overflowing
yippee
2024-02-24 21:56:43 +01:00
9734749c3e
implemented WHY2_OUTPUT_BYTE in decrypter
i choose literally the worst approach but YEAH...

...it doesn't work...

...it overflows...
2024-02-24 21:05:09 +01:00
226f9b3759
preventing encrypted bytes from being zero 2024-02-24 19:51:51 +01:00
23f7019883
defined why2_byte_format_length 2024-02-24 16:57:23 +01:00
bf64d848c7
declared why2_byte_format_length fn
you pass in string created using byte format and it returns the length of it
2024-02-24 16:55:10 +01:00
89d721fa9d
implemented WHY2_OUTPUT_BYTE in encrypter output 2024-02-24 12:52:06 +01:00
773591d452
implemented WHY2_OUTPUT_TEXT in encrypter 2024-02-24 12:48:38 +01:00
782e964fa2
made decrypter variables snake_case 2024-02-24 11:56:05 +01:00
58327f3046
made encrypter variables snake_case 2024-02-24 11:55:56 +01:00
21900e27cb
made encrypt & decrypt fn parameters snake_case 2024-02-24 11:51:31 +01:00
06ae819a82
added the WHY2_OUTPUT_TEXT enum to every why2_input_flags usage 2024-02-23 20:36:27 +01:00
3ef929665a
added WHY2_OUTPUT_FORMAT enum to why2_input_flags
you can basically specify if you want the "69.-420" output or you want messy string where each character is one output number iykwim
2024-02-23 20:33:37 +01:00
cb15d856de
why2_chat_generate_keys grammar fix
yessir i am an english-man fr fr
2024-02-23 20:27:00 +01:00
4564e2b63b
using base 62 for key save 2024-02-23 15:49:22 +01:00
836d3ec44a
implemented WHY2_CHAT_KEY_BASE macro 2024-02-23 11:55:29 +01:00
09a326a067
created WHY2_CHAT_KEY_BASE macro 2024-02-23 11:55:07 +01:00
4397122aaf
writing the rsa keys out 2024-02-23 11:47:33 +01:00
6ede019547
created pub & pri key location macros 2024-02-23 11:11:35 +01:00
923b9907db
renamed WHY2_CHAT_PUB_KEY_LOCATION to WHY2_CHAT_KEY_LOCATION 2024-02-23 11:08:19 +01:00
c89ae6c884
implemented WHY2_CHAT_RSA_EXPONENT in why2_chat_generate_keys 2024-02-23 11:04:21 +01:00
8599b06495
created WHY2_CHAT_RSA_EXPONENT macro
i mean it is convention AND it will make my life so much fucking easier
2024-02-23 11:03:53 +01:00
0c03ed3785
added key dir check into why2_chat_generate_keys 2024-02-23 10:59:38 +01:00
0e2da6ccb7
created WHY2_CHAT_PUB_KEY_LOCATION macro
contains path to key dir
2024-02-23 10:50:28 +01:00
1e925ec794
implemented why2_chat_generate_keys in client 2024-02-23 10:35:22 +01:00
c450adb0a8
added config init comments 2024-02-23 10:34:04 +01:00
f1a8e11ed1
using libgmp in makefile 2024-02-23 10:29:20 +01:00
55550e4ea4
defined why2_chat_generate_keys fn
and guess what! it doesn't save the keys, yet :dd
2024-02-23 10:27:00 +01:00
df4f7aae7d
created generate_prime fn
it uses gmp 😎
2024-02-23 10:25:07 +01:00
2beb4401ee
created WHY2_CHAT_PRIME_ITERS macro 2024-02-23 10:20:47 +01:00
9007dce4fd
created WHY2_CHAT_KEY_BITS macro 2024-02-23 10:14:50 +01:00
35f4b0447a
declered why2_chat_generate_keys fn 2024-02-23 10:13:47 +01:00
b1add93eca
added gmp dependency 2024-02-23 10:10:16 +01:00
07c82120dd
added unsupported distro dependency array 2024-02-23 09:52:33 +01:00
c294be679b
updated unsupported distro message formatting 2024-02-23 09:45:03 +01:00
13dff8514d
created crypto files 2024-02-23 09:40:34 +01:00
8fe73fafe9
implemented getrandom instead of rand
also made why2_generate_key's variables snake_case
2024-02-22 22:05:12 +01:00
20e805a8ad
removed why2_read_socket fn
using raw data in client loop
2024-02-22 09:31:46 +01:00
fd68b0d01a
implemented max/min username 2024-02-21 21:38:38 +01:00
c2b9c7c57a
possible loop problems fix 2024-02-21 21:35:13 +01:00
d30cd4f714
simplified json/config to int parse 2024-02-21 21:33:50 +01:00
32592aefb8
removed unused find_color fn 2024-02-21 21:25:49 +01:00
c163b63afc
implemented server_uname in why2_listen_server 2024-02-21 21:24:20 +01:00
57116ecd33
sending welcome packet 2024-02-21 20:56:21 +01:00
8a81c515df
added welcome parameter to packet sending 2024-02-21 20:50:45 +01:00
965395e9d4
implemented max_username_tries from server config 2024-02-21 20:29:40 +01:00
968498cf4e
implemented communication_time from server config 2024-02-21 20:18:39 +01:00
8c742b1884
implemented default_username from server config 2024-02-21 16:39:44 +01:00
e450032f26
implemented server_username from server config 2024-02-21 16:35:44 +01:00
06af6a801c
sending WHY2_CHAT_CODE_ACCEPT_MESSAGES earlier 2024-02-21 11:24:56 +01:00
3955561b82
fixed WHY2_CHAT_CONFIG_URL 2024-02-21 11:22:27 +01:00
f77f3a8c93
implemented config functions
way better now
2024-02-21 10:48:48 +01:00
41a0911a28
defined config functions
made it as least duplicate as possible
2024-02-21 10:42:19 +01:00
4d68d6e72b
declared config functions 2024-02-21 10:30:17 +01:00
0067524713
added some flags to server config file 2024-02-21 09:16:33 +01:00
a6f37b1aa3
added WHY2 into some chat-flags' identificator 2024-02-21 09:06:43 +01:00
92ab33a594
moved codes to why2-flags 2024-02-21 09:06:38 +01:00
532e22ef1d
moved config files to config dir 2024-02-20 20:49:33 +01:00
f0730dd4fd
fixed smol allocation size 2024-02-20 17:06:40 +01:00
0525c43b6f
reverted "removed pointless strlen from for loops"
This reverts commit 49b53ec5b1ffd1931e51c7d7c17a64a99e2bd54e.
2024-02-20 14:45:35 +01:00
3355d6ceea
unfuck reverts
This reverts commit 577c84c997c3b970ea9407d6727af5adc613487e.
2024-02-20 14:44:46 +01:00
577c84c997
reverted "removed unused read_socket_from_raw fn"
reverting commit f3eb26ed59cd09f066a266b9e72bfd94982e46cb.
2024-02-20 14:41:23 +01:00
49b53ec5b1
removed pointless strlen from for loops 2024-02-20 13:45:47 +01:00
f3eb26ed59
removed unused read_socket_from_raw fn 2024-02-20 13:32:16 +01:00
54aed2330b
fixed bad socket read in some cases
idk just reading it by bytes now and it seems to work
2024-02-20 13:31:54 +01:00
8f62b45d1d
protecting from invalid json syntax crashes 2024-02-20 13:24:31 +01:00
5d5f9be9ab
reverting "allocating sizeof(char*) in chat-misc"
reverts commit d6a0cc40fb20379bae02ace13a3569577c8b75b6.
2024-02-19 13:09:47 +01:00
f8ac3a5b1a
made code a bit safer 2024-02-19 12:48:26 +01:00
857a3afe95
removed gotos from why2_communicate_thread msg loop 2024-02-19 12:41:57 +01:00
1e6c297b57
added client accents todo 2024-02-19 12:29:40 +01:00
2408e0cef5
removed non-so-stupid gotos from core-misc
in the name of Satan, please do not cause any problems
2024-02-19 12:27:16 +01:00
b6bace31e2
removed stupid goto in logger 2024-02-19 12:17:44 +01:00
e77937e69e
removed goto from why2_listen_server loop
hopefully it won't cause even more errors
2024-02-19 12:14:11 +01:00
8da0383c82
fixed username formatting & iters 2024-02-19 11:06:07 +01:00
642092ebd4
removed unused includes 2024-02-18 20:39:39 +01:00
b960f7a5c6
removing non-ascii characters from messages 2024-02-18 20:14:32 +01:00
68140fe7c8
made formatting so fucking pretty 2024-02-18 19:31:07 +01:00
82df5f5b1c
fixed invalid_username formatting 2024-02-18 14:55:02 +01:00
5873d55d98
moved WHY2_CHAT_CODE_PICK_USERNAME code sending from loop 2024-02-18 14:27:10 +01:00
b1c104247c
added null check to chat-misc 2024-02-18 14:26:37 +01:00
64c21ed1fc
added why2-project job 2024-02-18 12:47:46 +01:00
02b04c7dc1
added why2-logger-test job 2024-02-18 12:22:02 +01:00
45afe8443a
ci typos fix 2024-02-18 11:25:31 +01:00
2837ace7f4
added comments to gitlab-ci 2024-02-18 11:23:38 +01:00
9c92ae394b
added why2-core-test into gitlab-ci 2024-02-18 11:20:34 +01:00
d765f287e6
try using rust:latest image 2024-02-18 11:09:45 +01:00
7ebb93fd2a
implemented BYPASS_CHECK in gitlab-ci 2024-02-18 11:03:22 +01:00
6363df1342
added BYPASS_CHECK to check_root 2024-02-18 11:01:42 +01:00
13555716bf
installing sudo and lsb-release in gitlab ci 2024-02-17 19:58:37 +01:00
3dc85fe1c5
removed sudo from gitlab ci 2024-02-17 19:52:12 +01:00
097da237ad
created gitlab ci with chat build 2024-02-17 19:49:27 +01:00
ec25dffbb3
created MIRRORS file
you won't believe me but it contains mirrors
2024-02-15 22:00:19 +01:00
d6a0cc40fb
allocating sizeof(char*) in chat-misc
possibly allocating too much but idk
2024-02-02 11:00:36 +01:00
0e9b5df58c
made send_to_all not run in a thread 2024-02-02 10:59:22 +01:00
b41d5703f4
checking decoded_buffer for NULL 2024-01-30 21:01:07 +01:00
f6d005551a
possibly fixed client crash
possibly means I have no fucking idea
2024-01-30 20:30:47 +01:00
c27b7d6a68
checking for duplicate usernames 2024-01-28 21:34:06 +01:00
9b95117a7c
minimal username length fix 2024-01-28 13:47:18 +01:00
b9e85da4dc
fixed max user ask count 2024-01-28 13:46:00 +01:00
cce133e56c
printing username in server 2024-01-28 13:39:03 +01:00
a6f50c2ddd
using client's username 2024-01-28 13:17:04 +01:00
79ddef2514
added get_username todo 2024-01-27 22:25:53 +01:00
d58efbd035
moved tries check to top of username loop 2024-01-27 22:22:36 +01:00
73d0f64fc9
implemented WHY2_MIN_USERNAME_LENGTH 2024-01-27 22:20:07 +01:00
1004b10a28
created WHY2_MIN_USERNAME_LENGTH flag 2024-01-27 22:17:26 +01:00
b21d39a35e
removed goto from username loop & implemented WHY2_MAX_USERNAME_TRIES 2024-01-27 22:13:20 +01:00
31db7c0622
created WHY2_MAX_USERNAME_TRIES flag 2024-01-27 22:13:00 +01:00
952658b281
added null terminating char to add_brackets 2024-01-27 22:10:32 +01:00
2121ec6786
checking for anon & server username
blocking them also
2024-01-27 18:40:12 +01:00
6970a65841
fixed client formatting again 2024-01-27 18:21:50 +01:00
135c3bd088
added username to connection_list node 2024-01-27 18:07:48 +01:00
5db46ba17d
created WHY2_DEFAULT_USERNAME flag 2024-01-27 17:58:25 +01:00
27facd5abd
fixed client formatting after username input 2024-01-27 17:55:20 +01:00
483ffa178d
server asking client for username 2024-01-27 17:47:05 +01:00
7042e3c971
catching WHY2_CHAT_CODE_INVALID_USERNAME and WHY2_CHAT_CODE_PICK_USERNAME as client 2024-01-27 17:46:45 +01:00
e36b2ffa61
created WHY2_CHAT_CODE_INVALID_USERNAME flag 2024-01-27 17:45:53 +01:00
e42632db6a
created WHY2_MAX_USERNAME_LENGTH flag 2024-01-27 17:45:29 +01:00
de449bd88a
created check_username function
this checks for characters that are not a-Z or 0-9
2024-01-27 17:44:39 +01:00
905c2004db
simplified server listening loop exit 2024-01-27 17:43:59 +01:00
d43882b38f
removed old useless testing code 2024-01-27 16:09:33 +01:00
8f9aaaba36
removed unused code 2024-01-27 15:55:41 +01:00
885aba79ab
fixed formatting on invalid command 2024-01-27 15:36:09 +01:00
7e35adfbb5
moved reading stuff from why2_communicate_thread to read_user function
chances this will break already working code is like 98.3% so yeah... Not 100% tho
2024-01-27 14:57:19 +01:00
f13688ef3f
Merge remote-tracking branch 'refs/remotes/origin/development' into development 2024-01-27 13:56:19 +01:00
808bffbdd6
removed useless yaml dependencies 2024-01-26 07:33:14 +01:00
7fd51adbfa
format fix 2024-01-25 21:51:11 +01:00
57eba2caf6
implemented auto_connect in client 2024-01-25 21:46:54 +01:00
85271c8aae
created workflow for building why2-chat
it also uploads the artifacts :))
2024-01-25 21:11:24 +01:00
d559173731
added chat-config library to gentoo config 2024-01-25 20:50:29 +01:00
abe76d79f0
added return value check to client & server getline 2024-01-25 11:23:54 +01:00
bd3eb8ed4a
removed duplicate tkch version
so yeah v1 and v2 were the same
2024-01-24 21:07:45 +01:00
7d37daa32d
preventing server from crashing on client crash 2024-01-24 18:29:02 +01:00
42f406f6b6
implemented tkch_version in why2_input_flags 2024-01-24 15:11:22 +01:00
bd92cd312d
tkch gen fix 2024-01-24 15:10:47 +01:00
d540c1ea88
removed tkch_version from tkch_gen parameters, using flags instead 2024-01-24 15:08:37 +01:00
d7aa65944b
moved WHY2_TEXT_KEY_CHAIN_VERSIONS into core-flags 2024-01-24 15:03:54 +01:00
12e4b7afe5
implemented tkch_versions in tkch_gen 2024-01-24 15:01:31 +01:00
7e33714f53
added WHY2_TEXT_KEY_CHAIN_VERSIONS enum as gen_tkch parameter 2024-01-24 14:54:30 +01:00
54da223e23
moved the historic tkch functions into enum versions 2024-01-24 14:47:48 +01:00
6e51e51a38
removed "old" prefix from gen_tkch_number functions 2024-01-24 14:38:12 +01:00
5a0766871d
created fourth old_gen_tkch function
this is the latest one which is being used to this day
2024-01-24 14:37:17 +01:00
5a88fbf045
created third old_gen_tkch function 2024-01-24 14:27:58 +01:00
abe720214c
created second old_gen_tkch function
this is gonna be a long day lol
2024-01-24 14:27:18 +01:00
a5298a8cbc
created first old_gen_tkch function
first version of tkch ever. I used this to send her my feelings. I couldn't do it normally cause I am loser, yk, so I used this fucking encryption. We're only friends now. But at least we talk to eachother. When she started ghosting me, I nearly hang myself. Thanks, Alex. Thanks that you are for me. I would have unalived myself if you haven't reposponded that time. Thanks so much. I still do love you.
2024-01-24 14:04:19 +01:00
bb0c07ef64
changed callback functions for tkch type to int 2024-01-24 13:55:42 +01:00
db1b1f8b22
removed fixed todo 2024-01-24 13:28:09 +01:00
a84047210d
created codacy workflow
this is for code quality check, also might delete this commit later. who knows
2024-01-24 12:30:48 +01:00
492563ee40
renamed why2_config_read to why2_toml_read
idk why i didnt do this at first
2024-01-24 12:18:12 +01:00
8f3a45f3ef
implemented why2_config_read in chat-misc 2024-01-24 12:16:15 +01:00
c8bfaedd9d
removed parses files 2024-01-24 12:10:16 +01:00
808b776be9
removed yaml dependency 2024-01-24 12:07:46 +01:00
1c1b893e09
implemented snake_case & non-root in workflows 2024-01-24 12:03:15 +01:00
5d443a0b74
checking for root access in install rule 2024-01-24 12:01:01 +01:00
40452f785d
changed Makefile's rule names to snake_case 2024-01-24 11:59:38 +01:00
b667f8ca3f
fixed user permission when installing
DO NOT RUN MAKEFILE USING sudo PLS  <3
2024-01-24 11:38:13 +01:00
58d05293ce
fixed rustup installation 2024-01-24 11:37:43 +01:00
553d9732e8
added cargo install to package managers 2024-01-23 21:59:20 +01:00
2f64743052
moved manual rust installation to gentoo 2024-01-23 21:56:17 +01:00
edba888b47
simplified rust install command 2024-01-23 21:50:35 +01:00
d06f79dd12
added source command to rust installation 2024-01-23 21:47:53 +01:00
5b3c2e9052
rust install command fix 2024-01-23 21:46:20 +01:00
990b67fc0a
added automaticall default to rust installation 2024-01-23 21:42:46 +01:00
bb7aca3ecf
implemented rust module in makefile
that was pretty huge update lol
2024-01-23 21:40:22 +01:00
7e04837119
added rust installation into config script 2024-01-23 21:39:41 +01:00
0736a0d442
created rust module for reading toml config files
Yes. Rust module in a LW C project. Yes. Am I stupid? Yes. Is somebody pointing at my head with a gun and forcing me to do this? Yes. Do I hate myself? Yes. love ya
2024-01-23 21:14:08 +01:00
758c9c1431
revert "added table parameter to why2_config_read"
This reverts commit f0376a73c28bb7d3caec0a8a761eb76ea1b1bb98.
2024-01-23 19:53:51 +01:00
78244e7e3e
removed tables from config files 2024-01-23 19:52:11 +01:00
f0376a73c2
added table parameter to why2_config_read 2024-01-23 19:45:12 +01:00
7d76a12708
changed yml to toml in config 2024-01-23 19:20:26 +01:00
74f9764e4b
changed config file types from yml to toml 2024-01-23 19:19:52 +01:00
b383094bd9
ignoring rust library output files 2024-01-23 19:02:38 +01:00
dfb7b54fbf
declared config_read stuff
you will facepalm few commits later, trust me :)))
2024-01-23 18:46:06 +01:00
c9e1567ae9
added missing license to memory related files 2024-01-23 18:29:33 +01:00
c31ea476a6
added c++ support to headers 2024-01-23 18:27:24 +01:00
ddbe899071
added message thread cleanup for server
also swaped the function names cause I am so smart
2024-01-21 13:44:31 +01:00
5fdd267907
fixed why2_clean_threads segfault client 2024-01-20 20:13:58 +01:00
72fcc4c3e5
running garbage collector at the end of client & server run 2024-01-20 16:01:19 +01:00
7ffb9b1d9c
fixed client segfault on ssqc 2024-01-20 15:48:34 +01:00
f71d3954f0
checked getline return value in client main
i hope these comints are sort of intelligent cause im  drunk as hell :dd
2023-11-18 20:22:04 +01:00
3d6f2b8293
Merge remote-tracking branch 'refs/remotes/origin/development' into development 2023-11-18 20:08:29 +01:00
586a8ed800
created ARCH_GENTOO_COMMON variable 2023-10-04 11:00:16 +02:00
34f416bace
marked config as executable 2023-10-04 10:56:15 +02:00
6d09e40e33
added gentoo installation into config 2023-10-04 09:57:51 +02:00
9b238b6d70
created WHY2_CHAT_CODE_ACCEPT_MESSAGES macro 2023-08-27 15:32:55 +02:00
c6957aadd7
changed libyaml name in debian dependencies 2023-08-27 12:30:45 +02:00
8e5eff52e4
added libyaml into dependencies 2023-08-27 12:26:50 +02:00
7c9e2211a5
implemented yml config in chat-misc 2023-08-27 12:19:46 +02:00
a0aabc547a
updated performance in why2_deallocate
now if you attempt to deallocate NULL, get_node doesn't go trough the whole list
2023-08-27 12:18:51 +02:00
b1062ad8df
moved config-related macros to config header 2023-08-27 12:01:26 +02:00
2682ef294e
added missing header include in parser 2023-08-27 11:59:15 +02:00
088ff17b1d
implemented WHY2_CHAT_SERVER_USERNAME macro 2023-08-27 11:56:23 +02:00
21a89400af
created WHY2_CHAT_SERVER_USERNAME macro 2023-08-27 11:56:14 +02:00
96babf734c
defined why2_yml_read
this definitely isn't code from chatgpt combined with my dumb-ass and some random stuff from stackoverflow, nah :))
2023-08-27 11:50:11 +02:00
4016478492
declared why2_yml_read 2023-08-27 11:48:32 +02:00
bb5d31b02e
added libyaml to LIBS_CHAT 2023-08-27 11:47:29 +02:00
9fb66c42bf
created parser files 2023-08-27 11:35:37 +02:00
15bc846db8
fixed .config directory path 2023-08-27 11:05:11 +02:00
c0f7461eab
added .config directory existence check 2023-08-26 19:14:11 +02:00
b11f092bda
replaced local macros with flags 2023-08-26 18:57:53 +02:00
902872d25c
implemented why2_chat_init_client_config
meow
2023-08-26 18:43:08 +02:00
bc77ccd04f
defined why2_chat_init_client_config 2023-08-26 18:41:43 +02:00
d2b8f414e7
added way to easily implement client config 2023-08-26 18:40:52 +02:00
821170764f
removed server.yml from WHY2_CHAT_CONFIG_URL 2023-08-26 18:31:40 +02:00
ed950e3abf
declared why2_chat_init_client_config 2023-08-26 18:22:42 +02:00
b1d368f375
added chat-flags config TODO 2023-08-26 18:22:18 +02:00
093cb2ad48
created client-side config file 2023-08-26 18:21:23 +02:00
bb74c5a52b
added license into server config 2023-08-26 18:18:10 +02:00
89e69df3cd
renamed why2_chat_init_config to why2_chat_init_server_config 2023-08-26 18:15:53 +02:00
9e95b283a4
implemented server-side config 2023-08-26 18:12:26 +02:00
c57cc6f068
removed unused include from flags 2023-08-26 18:07:04 +02:00
6df35b0f95
preparing for client-side config 2023-08-26 17:59:28 +02:00
c6746b3945
added NOT IMPLEMENTED note to user_pick_username 2023-08-26 17:39:07 +02:00
58ed9ed8d5
implemented llists in memory-identifiers && memory fix
lol haven't done anything in a while lmao
2023-08-26 17:07:47 +02:00
92e6632fbc
removed completed TODOs 2023-05-02 19:11:08 +02:00
884efa1a92
prepared WHY2_CHAT_CODEs handler 2023-05-02 19:08:43 +02:00
037521b871
sending WHY2_CHAT_CODE_PICK_USERNAME signal to client at connect 2023-05-02 18:55:21 +02:00
d25ca16f4e
created WHY2_CHAT_CODE_PICK_USERNAME macro
these will be sent on some events etc.
2023-05-02 18:54:55 +02:00
ca22dab5aa
added newline char to chat config 2023-05-02 18:42:06 +02:00
68a484cae1
fixed why2_send_socket's text_copy allocation size 2023-04-20 21:44:46 +02:00
9bcbe4c2d2
replaced json extension with yml in WHY2_CHAT_CONFIG
whoops
2023-04-20 21:36:20 +02:00
2f1c9dfe75
implemented why2_chat_init_config in chat-server 2023-04-20 21:35:41 +02:00
03c8587c67
implemented user variable in why2_chat_init_config 2023-04-20 21:35:18 +02:00
137f74bc3c
added user 'variable' into WHY2_CHAT_CONFIG_URL 2023-04-20 21:32:24 +02:00
258028359c
added missing memory include in config 2023-04-20 21:26:33 +02:00
0b14d2c1e0
added chat header files into why2.h 2023-04-20 21:24:42 +02:00
8dacaf7873
added cURL downloading into why2_chat_init_config 2023-04-20 21:23:53 +02:00
ab2bd02318
created WHY2_CHAT_CONFIG_URL macro
I will download the templates using cURL, I guess
2023-04-20 21:20:18 +02:00
23d0fced6f
basically defined why2_chat_init_config
//DO STUFF
2023-04-20 19:14:13 +02:00
89ad40a5a5
created basic why2_chat template config 2023-04-20 19:11:12 +02:00
a66e18be5a
created WHY2_CHAT_CONFIG macro 2023-04-20 10:21:44 +02:00
729a43d564
declared why2_chat_init_config function 2023-04-20 10:03:10 +02:00
6b691f1df8
created chat-config files 2023-04-20 09:54:48 +02:00
1af6cf45a1
optimalyzed send_to_all loop 2023-04-20 09:49:16 +02:00
41291fd345
removed server received messages 2023-04-20 09:45:39 +02:00
9630da569f
added missing return to why2_accept_thread 2023-04-20 09:42:20 +02:00
2d095daef2
added server connection message 2023-04-20 09:28:39 +02:00
460239b8bc
removed WHY2_CONNECT_MESSAGE macro 2023-04-20 09:09:53 +02:00
74e0453c5b
moved core-misc's replaceWord to global (as why2_replace) 2023-04-20 08:59:23 +02:00
876c24e3fb
created WHY2_CONNECT_MESSAGE macro 2023-04-20 08:56:48 +02:00
0bfeb17755
implemented why2-llist in chat-misc's connection list
sort of
2023-04-19 14:33:39 +02:00
83c173e22a
fixed stop_oldest_thread always working issue
no fucking way
2023-04-19 12:15:10 +02:00
fda282f491
removed inappropriate debug prints
pls don't view the changes for love of god
2023-04-19 12:00:53 +02:00
12a1dfda52
added same address todo 2023-04-19 11:20:12 +02:00
2af91e5aea
implemented double pointers in stop_oldest_thread 2023-04-19 11:09:26 +02:00
abb1805338
linking new head in why2_list_remove 2023-04-19 10:49:00 +02:00
b19a9deee7
kind of implemented llist in chat-misc
DO NOT USE THIS COMMIT, I USE IT JUST FOR SYNCING CODE BETWEEN DEVICES, IT IS UNSTABLE AS FUCK; thx <3
2023-04-18 21:10:42 +02:00
3ca7299086
passing double pointer into waiting_list 2023-04-18 21:09:12 +02:00
4fc6d36262
created local find_request function
it is basically why2_list_find but I changed it a bit
2023-04-18 21:08:18 +02:00
6857f5a67a
removed deallocation todo 2023-04-18 21:07:23 +02:00
c85f0d9669
added node value allocation by passed size 2023-04-14 15:30:50 +02:00
189d438a18
created WHY2_LIST_EMPTY macro 2023-04-13 16:44:54 +02:00
cec94db537
implemented why2_list_t in why2_list_find 2023-04-13 16:42:39 +02:00
57a03f348c
implemented why2_list_t in why2_list_remove_back 2023-04-13 16:42:02 +02:00
e7c9215fc9
implemented why2_list_t in why2_list_remove 2023-04-13 16:41:08 +02:00
97345b52c3
implemented why2_list_t in why2_list_push 2023-04-13 16:41:00 +02:00
ff2ec4078d
implemented why2_list_t in all llist-related functions' declarations 2023-04-13 16:34:52 +02:00
4234bab428
split why2-llist stuff into nodes and list
idk how to describe it
2023-04-13 16:20:02 +02:00
8b328b3e34
created why2_list_t typedef 2023-04-13 16:09:39 +02:00
b4cccf6d45
added list into every llist-related identificator 2023-04-13 16:06:40 +02:00
ad3716d5c1
reverted why2_llist implementation in core-flags
reverts bdc3fd59d2331faac3d241fc69d0561584bd059e
2023-04-13 16:01:47 +02:00
5d097ed766
added llist header into why2.h 2023-04-13 15:49:15 +02:00
2961beb599
added check_version segfault todo 2023-04-12 19:39:06 +02:00
bdc3fd59d2
implemented why2_llist in core-flags 2023-04-12 17:10:51 +02:00
acee29c374
declared why2_remove_back function
removes last element

so this is 1000th commit! Woah... i gone nuts

idk...

860917976483233792
2023-04-12 17:02:34 +02:00
3eaba0e0c4
moved llist_head into 1st parameter 2023-04-12 16:52:43 +02:00
10632e0070
created llist files
it contains basic llist function, stolen from memory.c
2023-04-12 16:50:00 +02:00
dac66c105d
removed unused chat-client definition
redefinition
2023-04-12 10:43:28 +02:00
2c8d81ed64
commented out json_file reading error return
valgrind had some beef with it
2023-04-12 10:33:35 +02:00
a4da24c4b5
using new thread to cancel waiting
so fixed that shit
2023-04-12 08:02:11 +02:00
46ea373beb
created waiting llist stuff 2023-04-12 08:01:32 +02:00
01f5165f8b
merged remote development into local
ntb
2023-04-11 07:46:56 +02:00
63f01d37e7
merged remote into local 2023-04-08 18:48:05 +02:00
afeafd78eb
removed why2_accept_thread close TODO 2023-04-05 14:24:40 +02:00
6a4034668b
implemented waiting llist in alarm_handler 2023-04-05 11:21:21 +02:00
278e880e62
created waiting llist
it contains only function for push
2023-04-05 11:12:01 +02:00
cdcc9e53b4
removed all why2_listen_server formatting todos 2023-04-05 10:21:47 +02:00
2991b1f2c3
removed server crash bug todo 2023-04-05 10:20:38 +02:00
aeed3cc5ee
added client timeout todo 2023-04-05 10:18:57 +02:00
c78a82e381
removed stuck TODO 2023-04-05 10:18:11 +02:00
28b2baae3c
fixed infinite waiting in communication loop
yeah I used signal.h (alert) and it works... yay
2023-04-05 10:16:53 +02:00
87bf911ba2
created WHY2_INVALID_POINTER macro
it is really bik number
2023-04-05 10:15:41 +02:00
d246948367
formatting fix 2023-04-02 18:28:50 +02:00
2f6bf93bf7
added infinity loop todo 2023-04-01 13:46:02 +02:00
0132c00f46
preventing memleaks on exit in why2_communicate_thread loop 2023-04-01 13:36:58 +02:00
ed8b328673
created WHY2_COMMUNICATION_TIME macro 2023-04-01 12:56:14 +02:00
8988b88b22
removed unused if statement from why2_communicate_thread loop 2023-04-01 12:49:26 +02:00
8f6a376a62
removed why2_connection_t
it was useless as hell
2023-04-01 12:43:49 +02:00
0a1cb72f5d
quitting communication with user on invalid packet receive 2023-03-31 18:36:09 +02:00
8d387df7d7
removing control characters from sent 2023-03-31 18:21:06 +02:00
efa1d24047
fixed invalid return in send_to_all 2023-03-31 18:12:56 +02:00
e0e82d2570
skipping read_socket_from_raw if invalid syntax was sent 2023-03-31 18:09:35 +02:00
af03d64699
skipping send_to_all if invalid syntax was sent 2023-03-31 17:50:40 +02:00
4b481d71ca
removing invalid json syntax on send 2023-03-31 17:47:05 +02:00
d9fe24b166
added json syntax todo 2023-03-25 18:20:06 +01:00
85834544aa
removing last char only when it's newline 2023-03-25 17:50:19 +01:00
7359c678d4
removed the n-word from debugging
whoopsie :D
2023-03-25 17:46:58 +01:00
1087e40cfc
sending json format in send_to_all 2023-03-25 17:39:52 +01:00
069338177e
added send_to_all TODO 2023-03-25 17:17:54 +01:00
f6c97a52c8
implemented json format in why2_communicate_thread 2023-03-25 16:37:58 +01:00
a8a6a8e07a
implemented raw socket stuff in why2_read_socket 2023-03-25 16:37:42 +01:00
259a9e7c82
created get_string_from_json_string function 2023-03-25 16:36:09 +01:00
885b99b7a8
added raw socket functions 2023-03-25 16:35:44 +01:00
04234d2938
implemented get_string_from_json in why2_read_socket 2023-03-24 20:45:16 +01:00
db8813b3ca
added chat-misc todos 2023-03-24 20:18:44 +01:00
01b8d716d6
added (currently) missing newline char to why2_listen_server print 2023-03-24 20:14:53 +01:00
f7a0db032e
decoding json packet in why2_read_socket 2023-03-24 20:01:15 +01:00
6f237888b1
sending json formatted packet
gonna make receiving decode this
2023-03-24 19:43:48 +01:00
0c285690eb
revert last commit (why2-memory in chat-misc)
for some reason it was causing segfault
2023-03-24 19:23:16 +01:00
f0574cae12
implemented why2-memory stuff in chat-misc 2023-03-24 19:12:22 +01:00
252c697377
implemented flags header rename 2023-03-12 15:02:06 +01:00
cd5d290a13
added WHY2-prefix at the beginning of chat-flags macros 2023-03-12 15:01:04 +01:00
b8b7b7cdff
renamed header common to flags 2023-03-12 14:59:53 +01:00
edbe07615c
removed includes from common.h 2023-03-12 14:59:07 +01:00
eedea02701
implemented CLEAR_AND_GO_UP in chat stuff 2023-03-12 14:45:58 +01:00
899b79941b
upgraded underline printing 2023-03-12 12:30:11 +01:00
92da77ff3e
fixed "local" message formatting
yeeees babyyyyyyyyyyyyy
2023-03-12 12:26:19 +01:00
c68f5a6f2b
changed why2_listen_server message formatting
it now looks good when message is received from somewhere/someone else; gonna fix own message formatting really soon

that was a good one lol
2023-03-12 12:22:42 +01:00
8cfe1e39ea
added missing chat-client listen_thread termination 2023-03-12 11:59:23 +01:00
258222160e
sort of fixed received message formatting
but actually not
2023-02-24 16:31:39 +01:00
3976c7e49c
added formatting TODO 2023-02-23 10:03:26 +01:00
c6093a8926
added terminating character to why2_read_socket 2023-02-23 09:54:10 +01:00
6fbbee7b68
added command handling to why2_communicate_thread 2023-02-23 09:05:16 +01:00
6e746b020b
server sending received to all clients
I shall fix the output lol
2023-02-22 14:37:18 +01:00
c6e98d120a
somehow defined why2_listen_server 2023-02-22 12:12:04 +01:00
0618de9584
declared why2_listen_server 2023-02-22 12:10:06 +01:00
0a331e97a8
sending received message to all clients 2023-02-22 12:07:26 +01:00
58d5c7ede8
made getting socket length more fancy 2023-02-22 11:03:15 +01:00
ba6aacb1b4
fixed deallocation order in why2_communicate_thread, again 2023-02-22 10:54:41 +01:00
66add23df5
fixed deallocation order in why2_communicate_thread 2023-02-22 10:47:14 +01:00
2c051f2cb2
fixed why2_communicate_thread thread id problem 2023-02-22 10:42:11 +01:00
4a298b94b3
added thread deallocation to chat-server 2023-02-22 10:36:37 +01:00
49978a8a53
changed why2_connection::thread type to UL 2023-02-22 10:33:42 +01:00
a5ec2c936b
added thread cancelling to why2_clean_threads 2023-02-22 10:19:36 +01:00
128cba4bf9
implemented why2_clean_threads in chat-server 2023-02-22 10:17:54 +01:00
459329e0d0
defined why2_clean_threads
meow
2023-02-22 10:16:01 +01:00
2b790a21fe
declared why2_clean_threads 2023-02-22 10:11:36 +01:00
b4c0af2739
implemented why2_connection_t in linked list 2023-02-22 10:09:58 +01:00
493724626c
created why2_connection_t struct
contains connection and pthread_t
2023-02-22 10:03:49 +01:00
736cd82240
removed why2_register_connection function 2023-02-22 10:01:03 +01:00
fbaef61ebc
removed client test print 2023-02-22 09:57:41 +01:00
1e7fbc03a8
added way to stop server 2023-02-22 09:56:23 +01:00
5a9073f595
fixed reading size
socket probably read wrongly
2023-02-22 09:43:12 +01:00
cbcfaaae92
added why2_read_socket invalid size TODO 2023-02-21 19:53:00 +01:00
ab46803a91
fixed why2_send_socket's send size 2023-02-21 19:48:28 +01:00
4b85ba17dd
why2_accept_thread param typo fix 2023-02-21 19:48:07 +01:00
54d90c7001
added missing parameter to why2_accept_thread 2023-02-21 19:38:15 +01:00
97e2d1d097
moved accept-loop to why2_accept_thread 2023-02-21 19:34:40 +01:00
89885de21e
added common todo 2023-02-21 19:29:08 +01:00
789a3ad09b
fixed sent size 2023-02-21 19:22:01 +01:00
c47c9ffece
moved registering connection to new thread 2023-02-21 18:59:44 +01:00
924c840e0d
fixed why2_read_socket allocation sizes 2023-02-21 15:38:00 +01:00
03418e7494
added server enabled message 2023-02-21 15:05:31 +01:00
1e77ff2878
typo fix 2023-02-21 15:00:59 +01:00
ad9f4b8f2d
implemented linked list in chat-server 2023-02-21 12:41:35 +01:00
3b85c5fc5a
added NULL check to all remove_node functions 2023-02-21 12:39:54 +01:00
f31216f387
added "why2_" at the beginning of chat-misc functions' identificators
i forgor again
2023-02-21 12:33:53 +01:00
4623f76f97
defined register_connection 2023-02-21 12:31:27 +01:00
0c632fce0e
created connection linked list in chat-misc 2023-02-21 12:30:58 +01:00
36b5ac7cfc
added license to common's top 2023-02-21 12:29:04 +01:00
ea15a24ed3
declared register_connection function 2023-02-21 12:26:27 +01:00
9f2ddb13dd
removed unused includes 2023-02-21 10:56:46 +01:00
22ff5a3e7d
moved server functions into why2-misc 2023-02-21 10:53:09 +01:00
a51cfae3b0
removed Makefile linking TODO 2023-02-21 10:47:14 +01:00
c0daeef31a
added why2-chat library compilation to Makefile
few changes heehee
2023-02-21 09:58:28 +01:00
0244536836
added missing license to why2-misc files 2023-02-21 07:59:09 +01:00
7123e88f97
moved send_socket into chat-misc 2023-02-21 07:58:12 +01:00
50a3a934d6
created misc source & header 2023-02-21 07:52:30 +01:00
04f3223fdb
moved chat-related files into main directory 2023-02-21 07:48:50 +01:00
c18e81ab7b
removed finished TODO 2023-02-21 07:42:31 +01:00
f185d89bc2
added underline to client startup 2023-02-21 07:41:35 +01:00
76448104b7
fixed compilation problems
linking library fok
2023-02-21 07:38:38 +01:00
54a039a60b
added IP select at client startup 2023-02-20 19:34:58 +01:00
2fb4c739b2
moved deallocation into communicate_thread 2023-02-20 19:26:08 +01:00
7e77f6ffda
added connect & exit messages 2023-02-20 19:19:40 +01:00
62fc06ab52
added way to exit client 2023-02-20 19:09:55 +01:00
5b855d21bd
added missing addr to client 2023-02-20 19:02:50 +01:00
97337f06db
keeping communication thread alive for MAX 24h 2023-02-20 18:58:32 +01:00
73a7be454b
moved communication to separate thread 2023-02-20 18:32:39 +01:00
daf6258222
preventing server from dying of invalid chars 2023-02-20 17:13:02 +01:00
7317e1da82
missing newline fix 2023-02-20 17:11:04 +01:00
fe8563ff5e
added pthread to common 2023-02-20 17:00:40 +01:00
368c57c285
looped client sending && TODOs 2023-02-20 14:12:26 +01:00
faa63577ee
optimized includes 2023-02-20 12:28:42 +01:00
6687d6e622
added content length to first two bytes of sent text in why2-chat 2023-02-20 12:27:50 +01:00
3a4f5ed7b6
added empty content check to read_socket 2023-02-18 17:05:30 +01:00
72305929b2
added invalid socket check to read_socket function 2023-02-15 20:06:08 +01:00
b52f86a9a6
merged remote development into local 2023-02-15 19:57:38 +01:00
de739b2121
simplified returningText generation in encrypter
fixed the weird strcat there
2023-02-15 19:43:08 +01:00
769bed7b18
changed read_socket's read usage to recv 2023-02-10 10:22:20 +01:00
7a450a19c4
added void parameter to chat-logger's main 2023-02-09 19:51:41 +01:00
e77e578be8
fixed read_socket memory problems 2023-02-09 19:46:38 +01:00
7b51acba52
implemented MAX_CONNECTIONS 2023-02-09 19:44:55 +01:00
01770f1f8d
defined MAX_CONNECTIONS in common 2023-02-09 19:42:38 +01:00
6f392c498d
fixed read_socket problems 2023-02-09 19:41:12 +01:00
649997088b
fixed server loop 2023-02-09 19:32:54 +01:00
6160ddbfad
renamed client's variables to snake_case 2023-02-09 19:28:06 +01:00
ccdc748dc9
added some basic test code to chat-client 2023-02-09 19:24:21 +01:00
611588dae8
created buildChat rule 2023-02-09 19:23:28 +01:00
f132844419
implemented why2_die in chat-server 2023-02-09 19:18:46 +01:00
2ea515ba38
fixed why2_die undefined reference 2023-02-09 19:15:27 +01:00
51f547d9df
added back removed include to misc 2023-02-09 19:00:27 +01:00
d261038c2c
added core-misc include in common 2023-02-09 18:50:05 +01:00
dcc4198e58
moved die function to core-misc 2023-02-09 18:49:04 +01:00
59b040d26e
declared why2_die 2023-02-09 18:47:42 +01:00
1e12e7a04f
removed SEND_LENGTH define 2023-02-09 18:45:19 +01:00
b7b902d542
implemented read_socket in accept-loop 2023-02-09 18:42:23 +01:00
c9c4f4bfd3
changed die function exit code to 1 2023-02-09 18:37:15 +01:00
edbe534a1f
created read_socket function 2023-02-09 18:36:51 +01:00
e859087763
included string in common 2023-02-09 18:27:50 +01:00
d151c6515c
looped accepting sockets 2023-02-09 18:25:45 +01:00
db0e862c6d
changed SERVER_PORT TO 1204 2023-02-09 18:23:54 +01:00
19f60173c9
added garbage collector run to die function 2023-02-09 18:19:28 +01:00
233c4641c9
included flags in common 2023-02-09 18:18:44 +01:00
9156d850a9
included stdlib in common 2023-02-09 18:16:05 +01:00
3e41101c85
defined SEND_LENGTH in common 2023-02-09 18:15:01 +01:00
5fb3270877
included memory to common 2023-02-09 18:14:34 +01:00
8d10cef2c0
changed SERVER_PORT to 944 2023-02-09 18:12:23 +01:00
64e5c830b2
simplified chat-server
it's just listening now, do not use this yet pls
2023-02-09 17:57:24 +01:00
2ee8d1c990
created installHeaderChat rule 2023-02-09 17:56:20 +01:00
3ac4f94559
added stdio include in common 2023-02-09 17:53:56 +01:00
135813ed67
defined die function 2023-02-09 17:53:42 +01:00
1147e53f61
defined SERVER_PORT
the port will change
2023-02-09 17:50:34 +01:00
b569e2a279
added some includes into common 2023-02-09 17:47:50 +01:00
6b1278cc06
created "common" header file 2023-02-09 17:39:11 +01:00
466d0570c1
removed thread lib from LIBS_CHAT 2023-02-09 17:36:27 +01:00
67b8f546fc
added license to chat-files 2023-02-09 17:19:49 +01:00
d124fe27c2
created LIBS_CHAT variable 2023-02-09 17:18:15 +01:00
a68a11d371
created basic server & client code
Oh, did I say "created"? I meant stole :)
2023-02-09 17:04:11 +01:00
e068e62c48
created buildChatServer rule 2023-02-09 09:15:57 +01:00
fc74bac727
created buildChatClient rule 2023-02-09 09:13:57 +01:00
6348fab4d9
created new why2-chat module 2023-02-09 09:09:26 +01:00
44 changed files with 3390 additions and 383 deletions

53
.github/workflows/codacy.yml vendored Normal file
View File

@ -0,0 +1,53 @@
# This is part of WHY2
# Copyright (C) 2022 Václav Šmejkal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
name: Codacy Scan
on:
push:
branches: [ "development" ]
schedule:
- cron: '40 22 12 4 2'
permissions:
contents: read
jobs:
codacy-security-scan:
permissions:
contents: read
security-events: write
actions: read
name: Codacy Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run Codacy Analysis
uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
gh-code-scanning-compat: true
max-allowed-issues: 2147483647
- name: Upload results file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif

73
.github/workflows/why2-chat-build.yml vendored Normal file
View File

@ -0,0 +1,73 @@
# This is part of WHY2
# Copyright (C) 2022 Václav Šmejkal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
name: Build WHY2-chat
on:
push:
branches: [ development ]
workflow_dispatch:
schedule:
- cron: '40 22 12 4 2'
jobs:
test-why2:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
client: ./out/why2-chat-client
server: ./out/why2-chat-server
configure: configure.sh
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: development
- if: matrix.os == 'ubuntu-latest'
name: Update packages
run: |
sudo apt update
# sudo apt upgrade
- name: Permissions
run: chmod +x ${{ matrix.configure }}
- name: Preparation
run: sudo ./${{ matrix.configure }}
- name: Install WHY2
run: make install
- name: Build Chat
run: make build_chat
- name: Upload Client
uses: actions/upload-artifact@v4
with:
name: WHY2 Chat Client
path: ${{ matrix.client }}
- name: Upload Server
uses: actions/upload-artifact@v4
with:
name: WHY2 Chat Server
path: ${{ matrix.server }}

View File

@ -59,10 +59,10 @@ jobs:
run: sudo apt install valgrind
- name: Install WHY2
run: sudo make install
run: make install
- name: Build WHY2 Test
run: make testCore
run: make test_core
- name: Test Lib
run: ./${{ matrix.output }}

View File

@ -59,10 +59,10 @@ jobs:
run: sudo apt install valgrind
- name: Install WHY2
run: sudo make install
run: make install
- name: Build WHY2 Test
run: make testLogger
run: make test_logger
- name: Test Lib
run: ./${{ matrix.output }}

View File

@ -53,7 +53,7 @@ jobs:
run: sudo ./${{ matrix.configure }}
- name: Install WHY2
run: sudo make install
run: make install
- name: Download WHY2 test project
run: curl -Lo ${{ matrix.test }}.c https://gist.github.com/ENGO150/d8419b6c31ffb68ebb930a5b41af8c73/raw

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ out/
misc/
logs/
vgcore.*
target/
Cargo.lock

80
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,80 @@
# This is part of WHY2
# Copyright (C) 2022 Václav Šmejkal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
variables:
CLIENT: "./out/why2-chat-client"
SERVER: "./out/why2-chat-server"
CORE_OUTPUT: "./out/why2-core-test"
CORE_APP: "why2"
LOGGER_OUTPUT: "./out/why2-logger-test"
LOGGER_APP: "why2-logger"
VALGRIND: "valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s"
why2-chat-build:
stage: build
image: rust:latest # Fixes cargo installation problems in ./configure.sh
script:
- apt update # Update repos
- apt install sudo lsb-release -y # Install needed stuff
- chmod +x configure.sh # Permissions
- sudo ./configure.sh # Preparation
- make install BYPASS_CHECK=true # Install WHY2
- make build_chat # Build Chat
artifacts:
paths:
- $CLIENT
- $SERVER
why2-core-test:
stage: build
image: rust:latest
script:
- apt update # Update repos
- apt install sudo lsb-release valgrind -y # Install needed stuff
- chmod +x configure.sh # Permissions
- sudo ./configure.sh # Preparation
- make install BYPASS_CHECK=true # Install WHY2
- make test_core # Build WHY2 Test
- ./$CORE_OUTPUT # Test Lib
- $CORE_APP # Test App
- $VALGRIND $CORE_OUTPUT # Test Lib by Valgrind
why2-logger-test:
stage: build
image: rust:latest
script:
- apt update # Update repos
- apt install sudo lsb-release valgrind -y # Install needed stuff
- chmod +x configure.sh # Permissions
- sudo ./configure.sh # Preparation
- make install BYPASS_CHECK=true # Install WHY2
- make test_logger # Build WHY2 Test
- ./$LOGGER_OUTPUT # Test Lib
- $LOGGER_APP # Test App
- $VALGRIND $LOGGER_OUTPUT # Test Lib by Valgrind
why2-project:
stage: build
image: rust:latest
script:
- apt update # Update repos
- apt install sudo lsb-release -y # Install needed stuff
- chmod +x configure.sh # Permissions
- sudo ./configure.sh # Preparation
- make install BYPASS_CHECK=true # Install WHY2
- curl -Lo test.c https://gist.github.com/ENGO150/d8419b6c31ffb68ebb930a5b41af8c73/raw # Download WHY2 test project
- cc test.c -lwhy2 -Wall -o test # Build WHY2 project
- ./test # Run Test

5
MIRRORS Normal file
View File

@ -0,0 +1,5 @@
- https://github.com/ENGO150/WHY2
- https://gitlab.com/ENGO150/why2
- https://gitlab.spseplzen.cz/smejkalv/why2
Contact me for access to private mirror.

View File

@ -16,6 +16,9 @@
# Compiler Settings
CC=cc
RC=cargo
CP=sudo install -m 755 # Not so compiler related but idk where to put it
RFLAGS=--manifest-path src/chat/config/Cargo.toml
CFLAGS=-Wall -Wextra -Werror -Wcomment -Wformat -Wformat-security -Wmain -Wnonnull -Wunused -std=gnu11 -O2 -g # Remove the '-g' flag if you want the smallest possible lib size
# Output Files
@ -29,15 +32,24 @@ OUTPUT_APP_CORE=$(OUTPUT)/$(PROJECT_NAME)-core-app
OUTPUT_TEST_LOGGER=$(OUTPUT)/$(PROJECT_NAME)-logger-test
OUTPUT_APP_LOGGER=$(OUTPUT)/$(PROJECT_NAME)-logger-app
OUTPUT_CHAT_CLIENT=$(OUTPUT)/$(PROJECT_NAME)-chat-client
OUTPUT_CHAT_SERVER=$(OUTPUT)/$(PROJECT_NAME)-chat-server
LIB_CHAT_CONFIG_OUT=./src/chat/config/target/release
# Source Code
SRC_CORE=./src/core/lib/*.c ./src/core/lib/utils/*.c
SRC_CORE_APP=./src/core/app/*.c
SRC_LOGGER=./src/logger/lib/*.c
SRC_LOGGER_APP=./src/logger/app/*.c
SRC_CHAT_CLIENT=./src/chat/main/client.c
SRC_CHAT_SERVER=./src/chat/main/server.c
SRC_CHAT_MISC=./src/chat/*.c
INCLUDE_DIR=./include
INCLUDE_CORE=$(INCLUDE_DIR)/*.h
INCLUDE_LOGGER=$(INCLUDE_DIR)/logger/*.h
INCLUDE_CHAT=$(INCLUDE_DIR)/chat/*.h
TEST_CORE=./src/core/lib/test/main.c
LIBS_CORE=-ljson-c -lcurl -lgit2
@ -47,6 +59,11 @@ TEST_LOGGER=./src/logger/lib/test/main.c
LIBS_LOGGER=$(LIB_CORE)
LIB_LOGGER=-l$(PROJECT_NAME)-logger
LIBS_LIB_CHAT=$(LIB_CORE) -lpthread -lgmp
LIB_CHAT=-l$(PROJECT_NAME)-chat
LIB_CHAT_CONFIG=$(LIB_CHAT)-config
LIBS_CHAT=$(LIB_CHAT) $(LIBS_LIB_CHAT) $(LIB_CHAT_CONFIG)
# Install Files
INSTALL_INCLUDE=/usr/include
INSTALL_LIBRARY=/usr/lib
@ -57,56 +74,86 @@ DOLLAR=$
##########
noTarget: # Do not use this, please <3
no_target: # Do not use this, please <3
@echo Hey you... You have to enter your target, too. Use \'install\' target for installing $(PROJECT_NAME)-core.
installHeaderCore:
for file in $(INCLUDE_CORE); do install -m 755 -D $(DOLLAR)file -t $(INSTALL_INCLUDE)/$(PROJECT_NAME); done
ln -sf $(INSTALL_INCLUDE)/$(PROJECT_NAME)/$(PROJECT_NAME).h $(INSTALL_INCLUDE)/$(PROJECT_NAME).h
check_root:
ifneq ($(BYPASS_CHECK),true)
@if [ "$(shell id -u)" = 0 ]; then\
echo "Do not run install rules as root.";\
exit 1;\
fi
endif
installHeaderLogger:
for file in $(INCLUDE_LOGGER); do install -m 755 -D $(DOLLAR)file -t $(INSTALL_INCLUDE)/$(PROJECT_NAME)/logger; done
install_header_core:
for file in $(INCLUDE_CORE); do $(CP) -D $(DOLLAR)file -t $(INSTALL_INCLUDE)/$(PROJECT_NAME); done
sudo ln -sf $(INSTALL_INCLUDE)/$(PROJECT_NAME)/$(PROJECT_NAME).h $(INSTALL_INCLUDE)/$(PROJECT_NAME).h
buildLibCore:
install_header_logger:
for file in $(INCLUDE_LOGGER); do $(CP) -D $(DOLLAR)file -t $(INSTALL_INCLUDE)/$(PROJECT_NAME)/logger; done
install_header_chat:
for file in $(INCLUDE_CHAT); do $(CP) -D $(DOLLAR)file -t $(INSTALL_INCLUDE)/$(PROJECT_NAME)/chat; done
build_lib_core:
$(MAKE) clean
$(CC) $(CFLAGS) -fPIC -c $(SRC_CORE)
$(CC) $(CFLAGS) -shared -o lib$(PROJECT_NAME).so *.o $(LIBS_CORE)
buildLibLogger:
build_lib_logger:
$(MAKE) clean
$(CC) $(CFLAGS) -fPIC -c $(SRC_LOGGER)
$(CC) $(CFLAGS) -shared -o lib$(PROJECT_NAME)-logger.so *.o $(LIBS_LOGGER)
installLibCore: buildLibCore
install -m 755 ./lib$(PROJECT_NAME).so $(INSTALL_LIBRARY)/lib$(PROJECT_NAME).so
build_chat_client:
$(CC) $(CFLAGS) $(SRC_CHAT_CLIENT) -o $(OUTPUT_CHAT_CLIENT) $(LIBS_CHAT)
installAppCore: appCore
install -m 755 $(OUTPUT_APP_CORE) $(INSTALL_BIN)/$(PROJECT_NAME)
build_chat_server:
$(CC) $(CFLAGS) $(SRC_CHAT_SERVER) -o $(OUTPUT_CHAT_SERVER) $(LIBS_CHAT)
installLibLogger: buildLibLogger
install -m 755 ./lib$(PROJECT_NAME)-logger.so $(INSTALL_LIBRARY)/lib$(PROJECT_NAME)-logger.so
build_lib_chat:
$(MAKE) clean
$(CC) $(CFLAGS) -fPIC -c $(SRC_CHAT_MISC)
$(RC) build $(RFLAGS) --release
$(CP) $(LIB_CHAT_CONFIG_OUT)/lib$(PROJECT_NAME)_chat_config.so $(INSTALL_LIBRARY)/lib$(PROJECT_NAME)-chat-config.so
$(CC) $(CFLAGS) -shared -o lib$(PROJECT_NAME)-chat.so *.o $(LIBS_LIB_CHAT)
installAppLogger: appLogger
install -m 755 $(OUTPUT_APP_LOGGER) $(INSTALL_BIN)/$(PROJECT_NAME)-logger
install_lib_core: build_lib_core
$(CP) ./lib$(PROJECT_NAME).so $(INSTALL_LIBRARY)/lib$(PROJECT_NAME).so
testCore:
install_app_core: app_core
$(CP) $(OUTPUT_APP_CORE) $(INSTALL_BIN)/$(PROJECT_NAME)
install_lib_logger: build_lib_logger
$(CP) ./lib$(PROJECT_NAME)-logger.so $(INSTALL_LIBRARY)/lib$(PROJECT_NAME)-logger.so
install_app_logger: app_logger
$(CP) $(OUTPUT_APP_LOGGER) $(INSTALL_BIN)/$(PROJECT_NAME)-logger
install_lib_chat: build_lib_chat
$(CP) ./lib$(PROJECT_NAME)-chat.so $(INSTALL_LIBRARY)/lib$(PROJECT_NAME)-chat.so
test_core:
$(CC) $(CFLAGS) $(TEST_CORE) -o $(OUTPUT_TEST_CORE) $(LIB_CORE)
testLogger:
test_logger:
$(CC) $(CFLAGS) $(TEST_LOGGER) -o $(OUTPUT_TEST_LOGGER) $(LIBS_LOGGER) $(LIB_LOGGER)
appCore:
app_core:
$(CC) $(CFLAGS) $(SRC_CORE_APP) -o $(OUTPUT_APP_CORE) $(LIB_CORE)
appLogger:
app_logger:
$(CC) $(CFLAGS) $(SRC_LOGGER_APP) -o $(OUTPUT_APP_LOGGER) $(LIBS_LOGGER) $(LIB_LOGGER)
clean:
$(RC) clean $(RFLAGS)
rm -rf $(OUTPUT)/* $(LOGS)/* *.o *.so vgcore.*
installHeader: installHeaderCore installHeaderLogger
installLibs: installLibCore installLibLogger
installApps: installAppCore installAppLogger
install: installHeader installLibs installApps clean
installTest: install testCore testLogger
build_chat: build_chat_server build_chat_client
install_header: install_header_core install_header_logger install_header_chat
install_libs: install_lib_core install_lib_logger install_lib_chat
install_apps: install_app_core install_app_logger
install: check_root install_header install_libs install_apps clean
install_test: install test_core test_logger
all: install

37
configure.sh Normal file → Executable file
View File

@ -24,16 +24,43 @@ if [[ $(id -u) != "0" ]] && [[ $1 != "force" ]]; then
exit 1
fi
COMMON="gcc make tmux curl"
ARCH_GENTOO_COMMON="$COMMON json-c libgit2 gmp"
# Get COMMAND
if [[ $DISTRO == "Arch" ]]; then
COMMAND="pacman -S --needed --noconfirm gcc json-c curl make libgit2 tmux"
COMMAND="pacman -S --needed --noconfirm $ARCH_GENTOO_COMMON"
elif [[ $DISTRO == "Ubuntu" ]] || [[ $DISTRO == "Debian" ]]; then
COMMAND="apt install -y gcc libjson-c-dev libcurl4-nss-dev make libgit2-dev tmux"
else
# 'Unsupported' distro
echo "It seems you are using unsupported distribution... Don't worry, just install 'gcc', 'json-c', 'curl', 'libgit2', 'tmux' and 'make' and you'll be fine."
COMMAND="apt install -y $COMMON libjson-c-dev libcurl4-nss-dev libgit2-dev libgmp-dev"
elif [[ $DISTRO == "Gentoo" ]]; then
COMMAND="emerge -vn $ARCH_GENTOO_COMMON"
# Add
echo "LDPATH=/usr/lib/libwhy2.so" > /etc/env.d/99why2-core
echo "LDPATH=/usr/lib/libwhy2-logger.so" > /etc/env.d/99why2-logger
echo "LDPATH=/usr/lib/libwhy2-chat.so" > /etc/env.d/99why2-chat
echo "LDPATH=/usr/lib/libwhy2-chat-config.so" > /etc/env.d/99why2-chat-config
env-update && source /etc/profile
else # 'Unsupported' distro
IFS=' ' read -r -a dependency_array <<< "$ARCH_GENTOO_COMMON" # Split into dependency_array
echo -e "It seems you are using unsupported distribution...\nDon't worry, just install these dependencies:\n"
for dependency in "${dependency_array[@]}" # Iter
do
echo "$dependency"
done
echo -e "\nand you'll be fine."
exit
fi
# Execute COMMAND
$COMMAND
# Install Rust
if ! [ -x "$(command -v cargo)" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y # Install Rust and components
source "$HOME/.cargo/env"
fi

49
include/chat/config.h Normal file
View File

@ -0,0 +1,49 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_CHAT_CONFIG_H
#define WHY2_CHAT_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/flags.h> //damn i really hate including headers in headers
//CONFIG MACROS
#define WHY2_CHAT_CONFIG_URL "https://raw.githubusercontent.com/ENGO150/WHY2/development/src/chat/config/"
#define WHY2_CHAT_CONFIG_SERVER "server.toml"
#define WHY2_CHAT_CONFIG_CLIENT "client.toml"
#define WHY2_CHAT_CONFIG_SERVER_USERS "server_users.toml" //LOGIN INFO CONFIG
void why2_chat_init_server_config(void); //CHECK IF SERVER CONFIG EXISTS, CREATE IT
void why2_chat_init_client_config(void); //Dementia is a term used to describe a group of symptoms affecting memory, thinking and social abilities. In people who have dementia, the symptoms interfere with their daily lives. Dementia isn't one specific disease. Several diseases can cause dementia. ...
char *why2_toml_read(const char* path, const char* key); //READ key FROM path TOML FILE
void why2_toml_write(const char *path, const char *key, const char *value); //WRITE value AS key INTO path TOML FILE
why2_bool why2_toml_contains(const char *path, const char *key); //CHECK IF path CONTAINS key
void why2_toml_read_free(char* s); //DEALLOCATE THE READ VALUE
char *why2_chat_server_config(char *key); //why2_toml_read BUT YOU DO NOT HAVE TO INCLUDE path
char *why2_chat_client_config(char *key); //hihi, *grabs shotgun quietly*
#ifdef __cplusplus
}
#endif
#endif

51
include/chat/crypto.h Normal file
View File

@ -0,0 +1,51 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_CHAT_CRYPTO_H
#define WHY2_CHAT_CRYPTO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/chat/config.h>
//MACROS
#define WHY2_CHAT_KEY_BITS 4096 //BITS..
#define WHY2_CHAT_PRIME_ITERS 100 //NUMBER OF ITERATIONS WHEN CHECKING PRIME NUMBER
#define WHY2_CHAT_RSA_EXPONENT "H33" //DEFAULT e IN BASE WHY2_CHAT_KEY_BASE
#define WHY2_CHAT_KEY_LOCATION WHY2_CONFIG_DIR "/keys" //KEYS LOCATION
#define WHY2_CHAT_PUB_KEY "pub"
#define WHY2_CHAT_PRI_KEY "pri"
#define WHY2_CHAT_KEY_BASE 62 //BASE IN THE GENERATED KEYS ARE STORED IN WHY2_CHAT_KEY_LOCATION
void why2_chat_init_keys(void); //INIT (POSSIBLY GENERATE) RSA KEYS
void why2_chat_deallocate_keys(void); //DEALLOCATE :) (NO SLUR HERE)
char *why2_get_chat_modulus(void); //GET THE RSA MODULUS
char *why2_get_chat_d(void); //GET THE RSA d
char *why2_chat_rsa_pub_encrypt(char *to_encrypt); //RSA ENCRYPT USING PUBLIC KEY
char *why2_chat_rsa_pri_decrypt(char *to_decrypt); //RSA DECRYPT USING PRIVATE KEY
#ifdef __cplusplus
}
#endif
#endif

68
include/chat/flags.h Normal file
View File

@ -0,0 +1,68 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_CHAT_COMMON_H
#define WHY2_CHAT_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
//MACROS
#define WHY2_SA struct sockaddr
#define WHY2_CHAT_SERVER_PORT 1204 //PORT
#define WHY2_MAX_CONNECTIONS 1000 //MAX USERS CONNECTED AT ONE TIME
#define WHY2_CLEAR_AND_GO_UP "\33[2K\r\033[A" //i mean read the name
#define WHY2_INVALID_POINTER (void*) 0xffffffffffffffff
//(SERVER -> CLIENT) CODES
#define WHY2_CHAT_CODE_ACCEPT_MESSAGES "code_000" //TELL CLIENT THEY CAN SEND MESSAGES
#define WHY2_CHAT_CODE_PICK_USERNAME "code_001" //TELL CLIENT TO PICK USERNAME
#define WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION "code_002" //TELL CLIENT TO END COMMUNICATION (just so they don't get segfault on server-side disconnect)
#define WHY2_CHAT_CODE_INVALID_USERNAME "code_003" //haha
#define WHY2_CHAT_CODE_LIST_SERVER "code_004" //SAME AS WHY2_CHAT_CODE_LIST BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_VERSION_SERVER "code_005" //SAME AS WHY2_CHAT_CODE_VERSION BUT BACK TO THE CLIENT
#define WHY2_CHAT_CODE_PM_SERVER "code_006" //SAME AS WHY2_CHAT_CODE_PM BUT BACK TO THE CLIENT
//(CLIENT -> SERVER) CODES
#define WHY2_CHAT_CODE_EXIT "code_999" //TELL SERVER YOU ARE ENDING COMMUNICATION
#define WHY2_CHAT_CODE_LIST "code_998" //TELL SERVER TO GIVE YOU ALL CONNECTED USERS
#define WHY2_CHAT_CODE_PM "code_997" //TELL SERVER TO SEND MESSAGE ONLY TO SPECIFIC ID
#define WHY2_CHAT_CODE_VERSION "code_996" //TELL SERVER TO GIVE YOU ITS VERSION
//COMMANDS
#define WHY2_CHAT_COMMAND_PREFIX "!" //the little thingy you write before the command names to make the program recognise them boy. You know? Like in minecraft you use /kill... Also, are you dumb?
#define WHY2_CHAT_COMMAND_EXIT "exit" //QUIT THE PROGRAM CMD
#define WHY2_CHAT_COMMAND_HELP "help" //PRINT ALL COMMANDS
#define WHY2_CHAT_COMMAND_LIST "list" //LIST ALL CONNECTIONS
#define WHY2_CHAT_COMMAND_PM "pm" //PRIVATE MESSAGES
#define WHY2_CHAT_COMMAND_VERSION "version" //COMPARE CLIENT VERSION AND SERVER VERSION
//SHORTCUTS CAUSE I'M LAZY BITCH
#define WHY2_CHAT_CODE_SSQC WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION
char *why2_chat_client_get_server_exit_cmd(); //GETTER AND SETTER FOR !exit FROM SERVER
void why2_chat_client_set_server_exit_cmd(char *cmd);
#ifdef __cplusplus
}
#endif
#endif

41
include/chat/misc.h Normal file
View File

@ -0,0 +1,41 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_CHAT_MISC_H
#define WHY2_CHAT_MISC_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/flags.h> //TODO: fuck this
void why2_send_socket(char *text, char *username, int socket); //send socket.... wtf did you expect
void *why2_communicate_thread(void *arg); //COMMUNICATION THREAD
void *why2_accept_thread(void *socket); //LOOP ACCEPTING CONNECTIONS
void why2_clean_connections(void); //CLOSE EVERY CONNECTION
void why2_clean_threads(void); //CLOSE EVERY RUNNING MESSAGE THREAD
void *why2_listen_server(void *socket); //LISTEN FOR OTHER's USERS MESSAGES
void *why2_getline_thread(WHY2_UNUSED void* arg); //START getline IN SEPARATE THREAD
void why2_trim_string(char **s); //REMOVES SPACES FROM END AND START OF *s
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,8 +19,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_DECRYPTER_H
#define WHY2_DECRYPTER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/flags.h>
why2_output_flags why2_decrypt_text(char *text, char *keyNew); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED
why2_output_flags why2_decrypt_text(char *text, char *key_new); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,8 +19,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_ENCRYPTER_H
#define WHY2_ENCRYPTER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/flags.h>
why2_output_flags why2_encrypt_text(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED
why2_output_flags why2_encrypt_text(char *text, char *key_new); //TEXT from WILL BE ENCRYPTED WITH KEY AND RETURNED
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,6 +19,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_FLAGS_H
#define WHY2_FLAGS_H
#ifdef __cplusplus
extern "C" {
#endif
//CONSTS
enum WHY2_EXIT_CODES //exit codes you fucking idiot
{
@ -29,9 +33,25 @@ enum WHY2_EXIT_CODES //exit codes you fucking idiot
WHY2_WHY2_UPDATE_FAILED = 3 //EXIT VALUE FOR UPDATE FAILED
};
//THESE ARE 'HISTORIC' VERSION FOR GENERATING tkch, SO YOU CAN DECRYPT OLD TEXT
enum WHY2_TEXT_KEY_CHAIN_VERSIONS
{
WHY2_v1, //FIRST VERSION. Replaced on May 28th 17:45:26 2022 UTC in commit 0d64f4fa7c37f0b57914db902258e279a71c7f9a.
WHY2_v2, //SECOND VERSION. Replaced on July 11th 17:12:41 2022 UTC in commit 0f01cde0f1e1a9210f4eef7b949e6d247072d3a6.
WHY2_v3 //THIRD VERSION. THE LATEST ONE
};
enum WHY2_OUTPUT_FORMAT
{
WHY2_OUTPUT_TEXT,
WHY2_OUTPUT_BYTE
};
#define WHY2_VERSION "v5.0" //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 WHY2_CONFIG_DIR "/home/{USER}/.config/WHY2"
#define WHY2_VERSIONS_NAME WHY2_CONFIG_DIR "/.versions.json" //do I have to explain this?
#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
@ -57,6 +77,8 @@ typedef struct
why2_bool no_check; //BOOLEAN FOR SKIPPING WHY2_VERSION CHECK
why2_bool no_output; //BOOLEAN FOR NOT PRINTING OUTPUT WHEN ENCRYPTING/DECRYPTING
why2_bool update; //BOOLEAN FOR UPDATING YOUR WHY WHY2_VERSION IF OLD IS USED
enum WHY2_TEXT_KEY_CHAIN_VERSIONS version; //VERSION OF tkch
enum WHY2_OUTPUT_FORMAT format; //VERSION OF tkch
} why2_input_flags;
typedef struct
@ -90,4 +112,8 @@ void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOpe
void why2_set_memory_identifier(char *new_memory_identifier);
void why2_reset_memory_identifier(void); //hmmm, what could reset mean.... huh
#ifdef __cplusplus
}
#endif
#endif

52
include/llist.h Normal file
View File

@ -0,0 +1,52 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_LLIST_H
#define WHY2_LLIST_H
#ifdef __cplusplus
extern "C" {
#endif
//MACROS
#define WHY2_LIST_EMPTY { NULL }
//TYPEDEFS
typedef struct _why2_node
{
void *value;
struct _why2_node *next;
} why2_node_t; //NODES
typedef struct
{
why2_node_t *head;
} why2_list_t; //SINGLE LINKED LIST MADE OF why2_node_t
//FUNCTIONS
void why2_list_push(why2_list_t *list, void *value, unsigned long size); //PUSH ELEMENT TO LIST BACK
void why2_list_remove(why2_list_t *list, why2_node_t *node); //REMOVE ELEMENT
void why2_list_remove_back(why2_list_t *list); //REMOVE LAST ELEMENT
why2_node_t *why2_list_find(why2_list_t *list, void *value); //FIND ELEMENT IN LIST
unsigned long why2_list_get_size(why2_list_t *list); //GET SIZE
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,6 +19,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_LOGGER_FLAGS_H
#define WHY2_LOGGER_FLAGS_H
#ifdef __cplusplus
extern "C" {
#endif
//CONSTS
enum WHY2_LOGGER_EXIT_CODES //exit codes you fucking idiot (2#)
{
@ -72,4 +76,8 @@ why2_log_flags why2_get_log_flags(void);
//SETTERS
void why2_set_log_flags(why2_log_flags why2_log_flagsNew);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,9 +19,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_LOGGER_LOGGER_H
#define WHY2_LOGGER_LOGGER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/logger/flags.h>
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
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,6 +19,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_LOGGER_UTILS_C
#define WHY2_LOGGER_UTILS_C
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/logger/flags.h>
void why2_deallocate_logger(why2_log_file logger); //USE THIS IF YOU WANT TO DEALLOCATE FILE POINTER RETURNED BY logger'S why2_init_logger
@ -27,4 +31,8 @@ why2_decrypted_output why2_decrypt_logger(why2_log_file logger); //PASS logger A
why2_log_file why2_empty_log_file(); //RETURN EMTPY why2_log_file WHAT THE FUCK DID YOU EXPECT
why2_decrypted_output why2_empty_decrypted_output(); //NO!
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,30 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WHY2_MEMORY_H
#define WHY2_MEMORY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <why2/flags.h>
void *why2_malloc(unsigned long size);
void *why2_calloc(unsigned long element, unsigned long size);
void *why2_realloc(void *pointer, unsigned long size);
@ -15,4 +39,10 @@ void why2_deallocate(void *pointer);
void why2_clean_memory(char *identifier); //identifier SPECIFIES WHICH NODES TO DEALLOCATE | THIS IS BASICALLY GARBAGE COLLECTOR | PASS why2_get_default_memory_identifier() FOR DEALLOCATING EVERYTHING
why2_bool why2_allocated(void *pointer); //CHECKS IF pointer WAS ALLOCATED USING WHY2-MEM
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,13 +19,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_MISC_H
#define WHY2_MISC_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/time.h>
#include <why2/flags.h>
void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION
void why2_generate_text_key_chain(char *key, int *text_key_chain, int text_key_chain_size); //GENERATES ARRAY FOR ENCRYPTION/DECRYPTION
char *why2_generate_key(int key_length); //GENERATE ENCRYPTION KEY
void why2_deallocate_output(why2_output_flags flags); //DEALLOCATES flags
void why2_directory(void); //GENERATE WHY2_CONFIG_DIR
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
@ -33,5 +38,12 @@ unsigned long why2_count_int_length(int number); //RETURNS LENGTH OF number
unsigned long why2_count_unused_key_size(char *text, char *key); //COUNT unused_key_size
unsigned long why2_count_repeated_key_size(char *text, char *key); //COUNT repeated_key_size
unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval finishTime); //COMPARE TIMES IN MICROSECONDS
void why2_die(char *exit_message); //PRINTS exit_message ERROR AND EXITS WITH CODE 1
char *why2_replace(char *string, char *old, char *new); //REPLACES old IN string WITH new
unsigned short why2_byte_format_length(char *s); //GET LENGTH OF s OF WHY2_OUTPUT_BYTE FORMAT
#ifdef __cplusplus
}
#endif
#endif

View File

@ -25,10 +25,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef WHY2_WHY2_H
#define WHY2_WHY2_H
#ifdef __cplusplus
extern "C" {
#endif
//CORE
#include <why2/decrypter.h>
#include <why2/encrypter.h>
#include <why2/flags.h>
#include <why2/llist.h>
#include <why2/memory.h>
#include <why2/misc.h>
@ -37,4 +42,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/logger/logger.h>
#include <why2/logger/utils.h>
//CHAT
#include <why2/chat/config.h>
#include <why2/chat/crypto.h>
#include <why2/chat/flags.h>
#include <why2/chat/misc.h>
#ifdef __cplusplus
}
#endif
#endif

9
src/chat/README Normal file
View File

@ -0,0 +1,9 @@
WHY2-Chat's Client & Server
===========================
*In development, do not use.*
WHY2's Chat is another encrypted and completely private communication.
All messages are encrypted with WHY2 and only you know the key (even the server can't decrypt the messages).
I am not responsible for any abuse of privacy.

148
src/chat/config.c Normal file
View File

@ -0,0 +1,148 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <why2/chat/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <curl/curl.h>
#include <why2/flags.h>
#include <why2/memory.h>
#include <why2/misc.h>
//LOCAL
enum CONFIG_TYPES
{
CLIENT,
SERVER
};
void init_config(char *filename)
{
//CREATE USER CONFIG FOLDER [THIS SHOULDN'T HAPPEN ON CLIENT, BUT IT'S NEEDED ON FRESH SERVERS]
why2_directory();
//GET THE CONFIG TYPE
char *buffer = why2_malloc(strlen(WHY2_CONFIG_DIR) + strlen(filename) + 2);
sprintf(buffer, "%s/%s", WHY2_CONFIG_DIR, filename);
char *path = why2_replace(buffer, "{USER}", getenv("USER"));
if (access(path, R_OK) != 0) //CONFIG DOESN'T EXIST
{
char *config_dir = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER"));
//CREATE CONFIG DIRECTORY
mkdir(config_dir, 0700);
CURL *curl = curl_easy_init();
FILE *file_buffer = why2_fopen(path, "w+");
buffer = why2_realloc(buffer, strlen(WHY2_CHAT_CONFIG_URL) + strlen(filename) + 1);
sprintf(buffer, "%s%s", WHY2_CHAT_CONFIG_URL, filename);
//DOWNLOAD CONTENT
curl_easy_setopt(curl, CURLOPT_URL, buffer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file_buffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
curl_easy_perform(curl);
//CLEANUP
curl_easy_cleanup(curl);
why2_deallocate(config_dir);
why2_deallocate(file_buffer);
}
//DEALLOCATION
why2_deallocate(path);
why2_deallocate(buffer);
}
char *config(char *key, enum CONFIG_TYPES type)
{
char *path = NULL;
switch (type) //GET path
{
case CLIENT:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER"));
break;
case SERVER:
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER"));
break;
default:
why2_die("CONFIG_TYPE not implemented!");
break;
}
//VALUE
char *value = why2_toml_read(path, key);
//DEALLOCATION
why2_deallocate(path);
return value;
}
//GLOBAL
void why2_chat_init_server_config(void)
{
init_config(WHY2_CHAT_CONFIG_SERVER);
//CHECK FOR USER CONFIG
char *user_pick_username = why2_chat_server_config("user_pick_username");
char *config_path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{USER}", getenv("USER"));
if (strcmp(user_pick_username, "true") == 0 && access(config_path, R_OK) != 0)
{
//CREATE THE CONFIG
FILE *config_file = why2_fopen(config_path, "w");
//WRITE SOMETHING POSITIVE TO THE CONFIG :) (i love you, ignore my aggressive ass)
fwrite("#haha no users registered, what a loser lol", 1, 43, config_file);
//CLEANUP
why2_deallocate(config_file);
}
//DEALLOCATION
why2_toml_read_free(user_pick_username);
why2_deallocate(config_path);
}
void why2_chat_init_client_config(void)
{
init_config(WHY2_CHAT_CONFIG_CLIENT);
}
char *why2_chat_server_config(char *key)
{
return config(key, SERVER);
}
char *why2_chat_client_config(char *key)
{
return config(key, CLIENT);
}

View File

@ -0,0 +1,27 @@
# This is part of WHY2
# Copyright (C) 2022 Václav Šmejkal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
[package]
name = "why2_chat_config"
version = "0.1.0"
edition = "2021"
[lib]
name = "why2_chat_config"
crate-type = ["cdylib"]
[dependencies]
toml = "*"

View File

@ -0,0 +1,18 @@
# This is part of WHY2
# Copyright (C) 2022 Václav Šmejkal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
auto_connect = false # Automatic connection to 'auto_connect_ip'
auto_connect_ip = "109.123.243.163" # See 'auto_connect'

View File

@ -0,0 +1,28 @@
# This is part of WHY2
# Copyright (C) 2022 Václav Šmejkal
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
user_pick_username = true # User will be prompted for their username on connect or will end up with default_username
server_name = "WHY2 Server" # Name of the server
server_username = "server" # Username server will use
default_username = "anon" # If user_pick_username is set to false, this will be used as client username
communication_time = 300 # Seconds waiting for client message before stopping communication
max_username_length = 20 # Maximal username length
min_username_length = 4 # Minimal username length
max_username_tries = 3 # Times asking client for username (if client tries to use invalid username)
max_message_length = 100 # Maximal message length

172
src/chat/config/src/lib.rs Normal file
View File

@ -0,0 +1,172 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::
{
os::raw::c_char,
fs::
{
read_to_string,
write,
},
ffi::
{
CString,
CStr,
},
};
use toml::Value;
#[no_mangle]
pub extern "C" fn why2_toml_read(path: *const c_char, key: *const c_char) -> *mut c_char
{
//CONVERT C STRINGS TO RUST STRINGS
let path_r = unsafe { CStr::from_ptr(path).to_string_lossy().into_owned() };
let key_r = unsafe { CStr::from_ptr(key).to_string_lossy().into_owned() };
//GET FILE CONTENT
let file_raw = match read_to_string(&path_r)
{
Ok(raw) => raw,
Err(e) => panic!("Could not read TOML config: {}\n{}", path_r, e),
};
//PARSE FILE
let data: toml::Value = match toml::from_str(&file_raw)
{
Ok(data) => data,
Err(e) => panic!("Could not parse TOML config: {}\n{}", path_r, e),
};
//GET VALUE BY key_r
let mut value = match data.get(&key_r)
{
Some(value) => value.to_string(),
None => panic!("Key \"{}\" not found in TOML config: {}", key_r, path_r),
};
value = value.replace("\"", "").trim().to_string(); //REMOVE QUOTES
CString::new(value).unwrap().into_raw()
}
#[no_mangle]
pub extern "C" fn why2_toml_write(path: *const c_char, key: *const c_char, value: *const c_char)
{
//CONVERT C STRINGS TO RUST STRINGS
let path_r = unsafe { CStr::from_ptr(path).to_string_lossy().into_owned() };
let key_r = unsafe { CStr::from_ptr(key).to_string_lossy().into_owned() };
let value_r = unsafe { CStr::from_ptr(value).to_string_lossy().into_owned() };
//GET FILE CONTENT
let file_raw = match read_to_string(&path_r)
{
Ok(raw) => raw,
Err(e) =>
{
eprintln!("Could not read TOML config: {}\n{}", path_r, e);
return;
},
};
//PARSE FILE
let mut data: Value = match toml::from_str(&file_raw)
{
Ok(data) => data,
Err(e) =>
{
eprintln!("Could not parse TOML config: {}\n{}", path_r, e);
return;
},
};
//INSERT VALUE (OR UPDATE)
if let Some(table) = data.as_table_mut()
{
table.insert(key_r, Value::String(value_r));
} else
{
eprintln!("Failed to get TOML table from file: {}", path_r);
return;
}
//CONVERT NEW DATA TO STRING
let updated_data = match toml::to_string(&data)
{
Ok(data) => data,
Err(e) =>
{
eprintln!("Failed to convert TOML data to string: {}\n{}", path_r, e);
return;
},
};
//WRITE NEW DATA
if let Err(e) = write(&path_r, updated_data)
{
eprintln!("Could not write to TOML config: {}\n{}", path_r, e);
}
}
#[no_mangle]
pub extern "C" fn why2_toml_contains(path: *const c_char, key: *const c_char) -> bool
{
//CONVERT C STRINGS TO RUST STRINGS
let path_r = unsafe { CStr::from_ptr(path).to_string_lossy().into_owned() };
let key_r = unsafe { CStr::from_ptr(key).to_string_lossy().into_owned() };
//GET FILE CONTENT
let file_raw = match read_to_string(&path_r)
{
Ok(raw) => raw,
Err(e) =>
{
eprintln!("Could not read TOML config: {}\n{}", path_r, e);
return false;
},
};
//PARSE FILE
let data: Value = match toml::from_str(&file_raw)
{
Ok(data) => data,
Err(e) =>
{
eprintln!("Could not parse TOML config: {}\n{}", path_r, e);
return false;
},
};
data.get(&key_r).is_some()
}
#[no_mangle]
pub extern "C" fn why2_toml_read_free(s: *mut c_char) //BECAUSE THIS IS RUST MODULE I HAVE TO CREATE A DEALLOCATING FUNCTION
{
unsafe //DON'T TRUST THIS, I DEFINITELY KNOW WHAT I'M DOING (idk)
{
if s.is_null() //bro
{
return;
}
drop(CString::from_raw(s)); //DROP THE PTR
}
}

205
src/chat/crypto.c Normal file
View File

@ -0,0 +1,205 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <why2/chat/crypto.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/random.h>
#include <why2/memory.h>
#include <why2/misc.h>
#include <gmp.h>
//DO NOT TOUCH THESE PLS :3
char *rsa_modulus = NULL; //THE RSA MODULUS
char *rsa_d = NULL; //THE RSA d
//LOCAL
void generate_prime(mpz_t x)
{
//RANDOM
gmp_randstate_t state;
gmp_randinit_default(state);
unsigned long random_buffer; //SEED
do
{
if (getrandom(&random_buffer, sizeof(unsigned long), GRND_NONBLOCK) == -1) why2_die("getrandom fn failed!");
//GENERATE RANDOM PRIME USING random_buffer SEED
gmp_randseed_ui(state, random_buffer);
mpz_urandomb(x, state, WHY2_CHAT_KEY_BITS);
mpz_nextprime(x, x);
} while (mpz_probab_prime_p(x, WHY2_CHAT_PRIME_ITERS) == 0); //CHECK FOR PRIME PROBABILITY
//DEALLOCATION
gmp_randclear(state);
}
void read_file(FILE *file, char **output)
{
//VARIABLES
int buffer_size;
char *buffer;
//GET LENGTH
fseek(file, 0, SEEK_END);
buffer_size = ftell(file);
rewind(file);
//READ
buffer = why2_calloc(buffer_size + 1, sizeof(char));
if (fread(buffer, buffer_size, 1, file) != 1) why2_die("Reading keyfile failed!");
buffer[buffer_size] = '\0';
//ASSIGN OUTPUT
*output = buffer;
}
char *exp_mod(char *to_exp, char *exponent)
{
//VARIABLES
char *output;
mpz_t m, c, n, e;
mpz_init(c);
//GET ALL STUFF
mpz_init_set_str(m, to_exp, 10);
mpz_init_set_str(n, why2_get_chat_modulus(), WHY2_CHAT_KEY_BASE);
mpz_init_set_str(e, exponent, WHY2_CHAT_KEY_BASE);
//ENCRYPT MESSAGE
mpz_powm(c, m, e, n);
output = why2_malloc(mpz_sizeinbase(c, 10) + 2); //ALLOCATE OUTPUT
mpz_get_str(output, 10, c); //GET OUTPUT
//DEALLOCATION
mpz_clears(m, c, n, e, NULL);
return output;
}
//GLOBAL
void why2_chat_init_keys(void)
{
//KEY FILES
FILE *public; //TECHNICALLY, PUBLIC KEY CONTAINS ONLY THE MODULUS AND PRIVATE CONTAINS ONLY THE d
FILE *private;
//GET PATH TO KEY DIR
char *path = why2_replace(WHY2_CHAT_KEY_LOCATION, "{USER}", getenv("USER"));
//ALLOCATE THE KEY PATHS
char *public_path = why2_malloc(strlen(path) + strlen(WHY2_CHAT_PUB_KEY) + 3);
char *private_path = why2_malloc(strlen(path) + strlen(WHY2_CHAT_PRI_KEY) + 3);
//GET THE ACTUAL KEY PATHS
sprintf(public_path, "%s/%s%c", path, WHY2_CHAT_PUB_KEY, '\0');
sprintf(private_path, "%s/%s%c", path, WHY2_CHAT_PRI_KEY, '\0');
//CHECK IF KEYS EXIST
if (access(path, R_OK) != 0)
{
mkdir(path, 0700);
//SOME USER OUTPUT
printf("You are probably running WHY2-Chat for the first time now.\nGenerating RSA keys...\n");
//VARIABLES
mpz_t p, q, e, d, n, phi_n, buffer_1, buffer_2;
mpz_inits(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL);
//GENERATE PRIMES
generate_prime(p);
generate_prime(q);
//SET e
mpz_set_str(e, WHY2_CHAT_RSA_EXPONENT, 10);
//GET n
mpz_mul(n, p, q);
//GET phi
mpz_sub_ui(buffer_1, p, 1);
mpz_sub_ui(buffer_2, q, 1);
mpz_mul(phi_n, buffer_1, buffer_2);
//COUNT d
mpz_invert(d, e, phi_n);
printf("Saving keys...\n");
//WRITE THE KEYS INTO KEY-FILES
public = why2_fopen(public_path, "w+");
private = why2_fopen(private_path, "w+");
mpz_out_str(public, WHY2_CHAT_KEY_BASE, n);
mpz_out_str(private, WHY2_CHAT_KEY_BASE, d);
//KEYGEN DEALLOCATION
mpz_clears(p, q, e, d, n, phi_n, buffer_1, buffer_2, NULL);
} else
{
//OPEN FILES
public = why2_fopen(public_path, "r");
private = why2_fopen(private_path, "r");
//READ THE KEYS
read_file(public, &rsa_modulus);
read_file(private, &rsa_d);
}
//DEALLOCATION
why2_deallocate(path);
why2_deallocate(public_path);
why2_deallocate(private_path);
why2_deallocate(public);
why2_deallocate(private);
}
void why2_chat_deallocate_keys(void)
{
why2_deallocate(rsa_modulus);
why2_deallocate(rsa_d);
}
char *why2_get_chat_modulus(void)
{
return rsa_modulus;
}
char *why2_get_chat_d(void)
{
return rsa_d;
}
char *why2_chat_rsa_pub_encrypt(char *to_encrypt)
{
return exp_mod(to_encrypt, WHY2_CHAT_RSA_EXPONENT);
}
char *why2_chat_rsa_pri_decrypt(char *to_decrypt)
{
return exp_mod(to_decrypt, why2_get_chat_d());
}

281
src/chat/main/client.c Normal file
View File

@ -0,0 +1,281 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <why2/chat/config.h>
#include <why2/chat/crypto.h>
#include <why2/chat/flags.h>
#include <why2/chat/misc.h>
#include <why2/flags.h>
#include <why2/memory.h>
#include <why2/misc.h>
why2_bool exited = 0; //USER ALREADY REQUESTED EXIT
int listen_socket; //THE SERVER SOCKET
void exit_client(WHY2_UNUSED int i) //guess what
{
if (exited) return;
exited = 1;
why2_send_socket(WHY2_CHAT_CODE_EXIT, NULL, listen_socket);
}
why2_bool command(char *input, char *command, char **arg)
{
why2_bool returning = 0;
//GET THE COMMANDS
char *full_cmd = why2_malloc(strlen(WHY2_CHAT_COMMAND_PREFIX) + strlen(WHY2_CHAT_COMMAND_EXIT) + 2);
sprintf(full_cmd, WHY2_CHAT_COMMAND_PREFIX "%s", command);
//CLEAR arg
why2_deallocate(*arg); //DEALLOCATION (why2_deallocate fn checks for NULL, don't you worry)
*arg = NULL;
if (strncmp(input, full_cmd, strlen(full_cmd)) == 0) //COMMAND WAS EXECUTED
{
if (strlen(full_cmd) == strlen(input) - 1) //COMMAND DOESN'T HAVE ARGS
{
returning = 1;
} else if (strlen(input) - 2 > strlen(full_cmd) && input[strlen(full_cmd)] == ' ') //COMMAND CONTAINS ARGS
{
returning = 1;
//GET THE ARGS
*arg = why2_malloc(strlen(input) - strlen(full_cmd) - 1); //ALLOCATE
for (unsigned long i = strlen(full_cmd) + 1; i < strlen(input) - 1; i++)
{
(*arg)[i - (strlen(full_cmd) + 1)] = input[i];
}
(*arg)[strlen(input) - strlen(full_cmd) - 2] = '\0'; //NULL TERM
why2_trim_string(arg);
}
}
//DEALLOCATE BUFFERS
why2_deallocate(full_cmd);
return returning;
}
void invalid(char *type)
{
printf("\nInvalid %s! Use \"" WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_HELP "\" for list of commands.\n\n>>> ", type);
fflush(stdout);
}
int main(void)
{
signal(SIGINT, exit_client); //HANDLE ^C
why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_client_config(); //CREATE client.toml CONFIGURATION
why2_chat_init_keys(); //CREATE RSA KEYS
listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
char *line = NULL;
void *return_line = NULL;
size_t line_length = 0;
pthread_t thread_buffer;
pthread_t thread_getline;
why2_bool ssqc = 0;
char *cmd_arg = NULL;
//DEFINE SERVER ADDRESS
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(WHY2_CHAT_SERVER_PORT);
//GET IP
printf("Welcome.\n\n");
char *auto_connect = why2_chat_client_config("auto_connect");
if (strcmp(auto_connect, "true") == 0) //USER ENABLED AUTOMATIC CONNECTION
{
char *auto_connect_ip = why2_chat_client_config("auto_connect_ip"); //GET IP
line = strdup(auto_connect_ip);
printf("%s\n", line);
why2_toml_read_free(auto_connect_ip);
} else
{
printf("Enter IP Address:\n>>> ");
if (getline(&line, &line_length, stdin) == -1) why2_die("Reading input failed.");
line_length = 3; //THIS IS FOR THE UNDERLINE THINGY
}
why2_toml_read_free(auto_connect);
server_addr.sin_addr.s_addr = inet_addr(line);
//PRINT UNDERLINE
for (unsigned long i = 0; i < strlen(line) + line_length; i++)
{
printf("#");
}
printf("\n\n\n");
free(line); //PREVENT FROM MEMORY LEAK
int connectStatus = connect(listen_socket, (WHY2_SA *) &server_addr, sizeof(server_addr)); //CONNECT
if (connectStatus < 0) why2_die("Connecting failed.");
pthread_create(&thread_buffer, NULL, why2_listen_server, &listen_socket); //LISTEN TO OTHER USERS
for (;;)
{
pthread_create(&thread_getline, NULL, why2_getline_thread, NULL);
pthread_join(thread_getline, &return_line);
if (return_line == WHY2_INVALID_POINTER) //SERVER QUIT COMMUNICATION
{
ssqc = 1;
break;
}
line = (char*) return_line;
why2_trim_string(&line);
if (line == NULL) line = strdup("");
printf(WHY2_CLEAR_AND_GO_UP);
//TODO: Remove accents
if (strncmp(line, WHY2_CHAT_COMMAND_PREFIX, strlen(WHY2_CHAT_COMMAND_PREFIX)) == 0) //OPTIMIZE COMMANDS
{
//COMMANDS
if (command(line, WHY2_CHAT_COMMAND_EXIT, &cmd_arg)) //USER REQUESTED PROGRAM EXIT
{
printf("Exiting...\n");
exit_client(0);
} else if (command(line, WHY2_CHAT_COMMAND_HELP, &cmd_arg)) //HELP CMD
{
printf
(
"\nCommands:\n---------\n%s\n\n>>> ",
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_HELP "\t\tPrints out all the commands. :)\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_PM " <ID> <MSG>\tSends private message to user.\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_LIST "\t\tLists all users and their IDs.\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_VERSION "\tCheck server version.\n"
WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT "\t\tExits the program."
);
fflush(stdout);
} else if (command(line, WHY2_CHAT_COMMAND_PM, &cmd_arg))
{
char *id; //PM RECEIVER
WHY2_UNUSED char *msg; //something racial
//CHECK ARGS VALIDITY
why2_bool valid_param = cmd_arg != NULL && strlen(cmd_arg) >= 3;
if (valid_param)
{
valid_param = 0;
for (unsigned long i = 1; i < strlen(cmd_arg); i++)
{
if (cmd_arg[i] == ' ')
{
valid_param = 1;
//EXTRACT FIRST ARG (ID)
id = why2_malloc(i + 1);
for (unsigned long j = 0; j < i; j++)
{
id[j] = cmd_arg[j];
}
id[i] = '\0';
if (atoi(id) <= 0) //INVALID ID PASSED
{
valid_param = 0;
why2_deallocate(id);
break;
}
//EXTRACT MESSAGE
msg = cmd_arg + i + 1;
break;
}
}
}
if (!valid_param) //INVALID ARGS
{
invalid("usage");
continue;
}
//BUILD MESSAGE TO SEND TO SERVER
char *final_message = why2_malloc(strlen(WHY2_CHAT_CODE_PM) + strlen(id) + strlen(msg) + 3);
sprintf(final_message, WHY2_CHAT_CODE_PM ";%s;%s%c", id, msg, '\0');
why2_send_socket(final_message, NULL, listen_socket); //SEND
//DEALLOCATION
why2_deallocate(id);
why2_deallocate(final_message);
} else if (command(line, WHY2_CHAT_COMMAND_LIST, &cmd_arg)) //LIST CMD
{
why2_send_socket(WHY2_CHAT_CODE_LIST, NULL, listen_socket);
} else if (command(line, WHY2_CHAT_COMMAND_VERSION, &cmd_arg)) //VERSION CMD
{
why2_send_socket(WHY2_CHAT_CODE_VERSION, NULL, listen_socket);
} else
{
invalid("command");
}
} else
{
why2_send_socket(line, NULL, listen_socket); //NULL IS SENT BECAUSE IT IS USELESS TO SEND USER FROM CLIENT - SERVER WON'T USE IT
free(line);
}
}
//DEALLOCATION
if (!ssqc)
{
pthread_cancel(thread_buffer);
free(line);
}
why2_deallocate(cmd_arg);
why2_chat_deallocate_keys(); //DEALLOCATE GETTERS FOR KEYS
why2_clean_memory(""); //RUN GARBAGE COLLECTOR
return 0;
}

86
src/chat/main/server.c Normal file
View File

@ -0,0 +1,86 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
#include <why2/chat/config.h>
#include <why2/chat/flags.h>
#include <why2/chat/misc.h>
#include <why2/memory.h>
#include <why2/misc.h>
int main(void)
{
why2_check_version(); //CHECK FOR UPDATES
why2_chat_init_server_config(); //CREATE server.toml CONFIGURATION
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
pthread_t thread;
size_t line_length_buffer = 0;
char *line_buffer = NULL;
if (listen_socket < 0) why2_die("Failed creating socket.");
//DEFINE SERVER ADDRESS
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(WHY2_CHAT_SERVER_PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
//BIND SOCKET
if (bind(listen_socket, (WHY2_SA *) &server_addr, sizeof(server_addr)) < 0) why2_die("Failed binding socket.");
//LISTEN
if (listen(listen_socket, WHY2_MAX_CONNECTIONS) < 0) why2_die("Binding failed.");
printf("Server enabled.\n\n");
pthread_create(&thread, NULL, why2_accept_thread, &listen_socket);
for (;;)
{
if (getline(&line_buffer, &line_length_buffer, stdin) == -1) why2_die("Reading input failed.");
if (strcmp(line_buffer, WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT "\n") == 0) //USER REQUESTED PROGRAM EXIT
{
printf("Exiting...\n");
break;
}
}
//QUIT COMMUNICATION
why2_clean_connections(); //STOP LISTENING; DISCONNECT ALL USERS
why2_clean_threads(); //STOP WAITING FOR MESSAGES
//DEALLOCATION
free(line_buffer);
close(listen_socket);
pthread_cancel(thread);
why2_clean_memory(""); //RUN GARBAGE COLLECTOR
return 0;
}

1129
src/chat/misc.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
int main(void)
{
//SET FLAGS
why2_set_flags((why2_input_flags) {1, 1, 0});
why2_set_flags((why2_input_flags) { 1, 1, 0, WHY2_v3, WHY2_OUTPUT_TEXT });
//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);

View File

@ -27,129 +27,179 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/memory.h>
#include <why2/misc.h>
why2_output_flags why2_decrypt_text(char *text, char *keyNew)
why2_output_flags why2_decrypt_text(char *text, char *key_new)
{
//CHECK VARIABLE
unsigned char checkExitCode;
unsigned char check_exit_code;
//TIME VARIABLES
struct timeval startTime;
struct timeval finishTime;
gettimeofday(&startTime, NULL);
struct timeval start_time;
struct timeval finish_time;
gettimeofday(&start_time, NULL);
//CHECK FOR ACTIVE WHY2_VERSION
if ((checkExitCode = why2_check_version()) != WHY2_SUCCESS)
if ((check_exit_code = why2_check_version()) != WHY2_SUCCESS)
{
return why2_no_output(checkExitCode);
return why2_no_output(check_exit_code);
}
//CHECK FOR INVALID text
if ((checkExitCode = why2_check_text(text)) != WHY2_SUCCESS)
if ((check_exit_code = why2_check_text(text)) != WHY2_SUCCESS)
{
return why2_no_output(checkExitCode);
return why2_no_output(check_exit_code);
}
//CHECK FOR INVALID key
if ((checkExitCode = why2_check_key(keyNew)) != WHY2_SUCCESS)
if ((check_exit_code = why2_check_key(key_new)) != WHY2_SUCCESS)
{
return why2_no_output(checkExitCode);
return why2_no_output(check_exit_code);
}
//REDEFINE keyLength
why2_set_key_length(strlen(keyNew));
why2_set_key_length(strlen(key_new));
//VARIABLES
char *returningText;
int numberBuffer = 1;
int usedTextDeallocationBuffer = 0;
char *textBuffer = NULL;
int textKeyChainLength;
int *textKeyChain;
char *key = why2_strdup(keyNew); //COPY keyNew TO key
int *encryptedTextKeyChain;
char *used_text = why2_strdup(text); //COPY text TO used_text
char *returning_text;
int number_buffer = 0;
int used_text_deallocation_buffer = 0;
char *text_buffer = NULL;
int text_key_chainLength;
int *text_key_chain;
char *key = why2_strdup(key_new); //COPY key_new TO key
int *encrypted_text_key_chain;
char *used_text = NULL; //COPY text TO used_text
//GET LENGTH OF returningText AND textKeyChain
for (int i = 0; i < (int) strlen(used_text); i++)
if (why2_get_flags().format == WHY2_OUTPUT_BYTE)
{
if (used_text[i] == why2_get_encryption_separator()) numberBuffer++;
//REBUILD THE BYTE FORMAT AS TEXT FORMAT
int *encrypted_input = why2_malloc(sizeof(int) * why2_byte_format_length(text));
char *text_copy = why2_strdup(text);
//GET ENCRYPTED NUMBERS
for (unsigned short i = 0; i < why2_byte_format_length(text_copy); i++)
{
for (unsigned short j = 2 + (i * 2); j <= 3 + (i * 2); j++)
{
//ENSURE THERE IS NO \0 (REVERSED)
if (text_copy[j] == -128) text_copy[j] = 0;
}
//PUT TOGETHER
encrypted_input[i] = (text_copy[3 + (i * 2)] << 7) | text_copy[2 + (i * 2)];
//ALSO COUNT REQUIRED SIZE
number_buffer += why2_count_int_length(encrypted_input[i]);
}
number_buffer += why2_byte_format_length(text_copy); //ADD THE SEPARATORS (I didn't remove one cause 1 index will be empty at used_text end)
used_text = why2_calloc(number_buffer, sizeof(char));
for (unsigned short i = 0; i < why2_byte_format_length(text_copy); i++)
{
number_buffer = why2_count_int_length(encrypted_input[i]);
text_buffer = why2_realloc(text_buffer, number_buffer + 1);
sprintf(text_buffer, "%d", encrypted_input[i]);
strcat(used_text, text_buffer);
if (i != why2_byte_format_length(text_copy) - 1)
{
used_text[strlen(used_text)] = why2_get_encryption_separator();
}
}
//DEALLOCATION
why2_deallocate(encrypted_input);
why2_deallocate(text_buffer);
why2_deallocate(text_copy);
} else if (why2_get_flags().format == WHY2_OUTPUT_TEXT)
{
used_text = why2_strdup(text);
}
//SET LENGTH (numberBuffer)
returningText = why2_calloc(numberBuffer + 1, sizeof(char));
textKeyChain = why2_malloc(sizeof(int) * numberBuffer);
encryptedTextKeyChain = why2_malloc(sizeof(int) * numberBuffer);
textKeyChainLength = numberBuffer;
number_buffer = 1;
//LOAD textKeyChain
why2_generate_text_key_chain(key, textKeyChain, numberBuffer);
//LOAD encryptedTextKeyChain
for (int i = 0; i < textKeyChainLength; i++)
//GET LENGTH OF returning_text AND text_key_chain
for (int i = 0; i < (int) strlen(used_text); i++)
{
numberBuffer = 0;
if (used_text[i] == why2_get_encryption_separator()) number_buffer++;
}
//SET LENGTH (number_buffer)
returning_text = why2_calloc(number_buffer + 1, sizeof(char));
text_key_chain = why2_malloc(sizeof(int) * number_buffer);
encrypted_text_key_chain = why2_malloc(sizeof(int) * number_buffer);
text_key_chainLength = number_buffer;
//LOAD text_key_chain
why2_generate_text_key_chain(key, text_key_chain, number_buffer);
//LOAD encrypted_text_key_chain
for (int i = 0; i < text_key_chainLength; i++)
{
number_buffer = 0;
//GET LENGTH OF EACH CHARACTER
for (int j = 0; j < (int) strlen(used_text); j++)
{
if (used_text[j] == why2_get_encryption_separator()) break;
numberBuffer++;
number_buffer++;
}
textBuffer = why2_realloc(textBuffer, numberBuffer + 1);
text_buffer = why2_realloc(text_buffer, number_buffer + 1);
//CLEAN (POSSIBLY EXISTING) JUNK in textBuffer
for (int j = 0; j <= numberBuffer; j++)
//CLEAN (POSSIBLY EXISTING) JUNK in text_buffer
for (int j = 0; j <= number_buffer; j++)
{
textBuffer[j] = '\0';
text_buffer[j] = '\0';
}
//LOAD textBuffer
//LOAD text_buffer
for (int j = 0; j < (int) strlen(used_text); j++)
{
textBuffer[j] = used_text[j];
text_buffer[j] = used_text[j];
if (numberBuffer == j) break;
if (number_buffer == j) break;
}
encryptedTextKeyChain[i] = atoi(textBuffer);
encrypted_text_key_chain[i] = atoi(text_buffer);
used_text += numberBuffer + 1;
usedTextDeallocationBuffer += numberBuffer + 1;
used_text += number_buffer + 1;
used_text_deallocation_buffer += number_buffer + 1;
}
//DECRYPT TEXT
for (int i = 0; i < textKeyChainLength; i++)
for (int i = 0; i < text_key_chainLength; i++)
{
textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], encryptedTextKeyChain[i]);
text_key_chain[i] = why2_get_encryption_operation()(text_key_chain[i], encrypted_text_key_chain[i]);
}
//LOAD returningText
for (int i = 0; i < textKeyChainLength; i++)
//LOAD returning_text
for (int i = 0; i < text_key_chainLength; i++)
{
returningText[i] = textKeyChain[i];
returning_text[i] = text_key_chain[i];
}
//GET FINISH TIME
gettimeofday(&finishTime, NULL);
gettimeofday(&finish_time, NULL);
//LOAD output
why2_output_flags output =
{
returningText, //DECRYPTED TEXT
returning_text, //DECRYPTED TEXT
key, //USED KEY
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_count_unused_key_size(returning_text, key), // NUMBER OF WHY2_UNUSED CHARS IN KEY
why2_count_repeated_key_size(returning_text, key), //NUMBER OF REPEATED CHARS IN KEY
why2_compare_time_micro(start_time, finish_time), // ELAPSED TIME
WHY2_SUCCESS //EXIT CODE
};
//DEALLOCATION
why2_deallocate(textKeyChain);
why2_deallocate(encryptedTextKeyChain);
why2_deallocate(textBuffer);
why2_deallocate(used_text - usedTextDeallocationBuffer);
why2_deallocate(text_key_chain);
why2_deallocate(encrypted_text_key_chain);
why2_deallocate(text_buffer);
why2_deallocate(used_text - used_text_deallocation_buffer);
return output;
}

View File

@ -26,47 +26,47 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/memory.h>
#include <why2/misc.h>
why2_output_flags why2_encrypt_text(char *text, char *keyNew)
why2_output_flags why2_encrypt_text(char *text, char *key_new)
{
//CHECK VARIABLE
unsigned char checkExitCode;
unsigned char check_exit_code;
//TIME VARIABLES
struct timeval startTime;
struct timeval finishTime;
gettimeofday(&startTime, NULL);
struct timeval start_time;
struct timeval finish_time;
gettimeofday(&start_time, NULL);
//CHECK FOR ACTIVE WHY2_VERSION
if ((checkExitCode = why2_check_version()) != WHY2_SUCCESS)
if ((check_exit_code = why2_check_version()) != WHY2_SUCCESS)
{
return why2_no_output(checkExitCode);
return why2_no_output(check_exit_code);
}
//CHECK FOR INVALID text
if ((checkExitCode = why2_check_text(text)) != WHY2_SUCCESS)
if ((check_exit_code = why2_check_text(text)) != WHY2_SUCCESS)
{
return why2_no_output(checkExitCode);
return why2_no_output(check_exit_code);
}
why2_set_memory_identifier("core_decrypt");
//VARIABLES
char *key = NULL;
char *returningText;
char *textBuffer = NULL;
int *textKeyChain = why2_malloc(sizeof(int) * strlen(text));
int numberBuffer = 0;
char *returning_text = NULL;
char *text_buffer = NULL;
int *text_key_chain = why2_malloc(sizeof(int) * strlen(text));
int number_buffer = 0;
if (keyNew != NULL)
if (key_new != NULL)
{
//CHECK FOR INVALID key
if ((checkExitCode = why2_check_key(keyNew)) != WHY2_SUCCESS)
if ((check_exit_code = why2_check_key(key_new)) != WHY2_SUCCESS)
{
why2_clean_memory("core_decrypt");
return why2_no_output(checkExitCode);
return why2_no_output(check_exit_code);
}
key = why2_strdup(keyNew);
key = why2_strdup(key_new);
//REDEFINE keyLength
why2_set_key_length(strlen(key));
@ -75,61 +75,85 @@ why2_output_flags why2_encrypt_text(char *text, char *keyNew)
key = why2_generate_key(why2_get_key_length());
}
//LOAD textKeyChain
why2_generate_text_key_chain(key, textKeyChain, strlen(text));
//LOAD text_key_chain
why2_generate_text_key_chain(key, text_key_chain, strlen(text));
//ACTUALLY ENCRYPT TEXT
for (int i = 0; i < (int) strlen(text); i++)
{
textKeyChain[i] = why2_get_encryption_operation()(textKeyChain[i], (int) text[i]);
text_key_chain[i] = why2_get_encryption_operation()(text_key_chain[i], (int) text[i]);
}
//COUNT REQUIRED SIZE FOR returningText
for (int i = 0; i < (int) strlen(text); i++)
//OUTPUT FORMATS
if (why2_get_flags().format == WHY2_OUTPUT_TEXT) //NORMAL 420.-69 FORMAT
{
numberBuffer += why2_count_int_length(textKeyChain[i]);
}
//ALLOCATE returningText (WITH THE SEPARATORS)
returningText = why2_calloc(numberBuffer + strlen(text), sizeof(char));
//LOAD returningText
for (int i = 0; i < (int) strlen(text); i++)
{
numberBuffer = sizeof(int) * why2_count_int_length(textKeyChain[i]);
textBuffer = why2_realloc(textBuffer, numberBuffer);
sprintf(textBuffer, "%d", textKeyChain[i]);
strcat(returningText, textBuffer);
if (i != (int) strlen(text) - 1)
//COUNT REQUIRED SIZE FOR returning_text
for (int i = 0; i < (int) strlen(text); i++)
{
textBuffer = why2_realloc(textBuffer, 2);
sprintf(textBuffer, "%c", why2_get_encryption_separator());
number_buffer += why2_count_int_length(text_key_chain[i]);
}
strcat(returningText, textBuffer);
//ALLOCATE returning_text (WITH THE SEPARATORS)
returning_text = why2_calloc(number_buffer + strlen(text), sizeof(char));
//LOAD returning_text
for (int i = 0; i < (int) strlen(text); i++)
{
number_buffer = sizeof(int) * why2_count_int_length(text_key_chain[i]);
text_buffer = why2_realloc(text_buffer, number_buffer);
sprintf(text_buffer, "%d", text_key_chain[i]);
strcat(returning_text, text_buffer);
if (i != (int) strlen(text) - 1)
{
returning_text[strlen(returning_text)] = why2_get_encryption_separator();
}
}
} else if (why2_get_flags().format == WHY2_OUTPUT_BYTE) //FUCKED BUT SHORT(ER) OUTPUT
{
number_buffer = (strlen(text) + 1) * 2; //EACH CHARACTER WILL BE SPLIT INTO TWO CHARS AND FIRST TWO WILL BE LENGTH OF text
returning_text = why2_calloc(number_buffer + 1, sizeof(char)); //ALLOCATE
//SET LENGTH
returning_text[0] = (strlen(text) & 0x7f) + 1; //+1 BECAUSE WE DON'T WANT \0
returning_text[1] = (strlen(text) >> 7) + 1;
//PUT THE text_key_chain INTO returning_text DIRECTLY
for (unsigned long i = 0; i < strlen(text); i++)
{
//BUILD returning_text
returning_text[2 + (i * 2)] = text_key_chain[i] & 0x7f;
returning_text[3 + (i * 2)] = (text_key_chain[i] >> 7) | ((text_key_chain[i] < 0) ? 0x80 : 0);
for (unsigned long j = 2 + (i * 2); j <= 3 + (i * 2); j++)
{
//ENSURE THERE IS NO \0
if (returning_text[j] == 0) returning_text[j] = -128;
}
}
}
//GET FINISH TIME
gettimeofday(&finishTime, NULL);
gettimeofday(&finish_time, NULL);
//LOAD output
why2_output_flags output =
{
returningText, //ENCRYPTED TEXT
returning_text, //ENCRYPTED TEXT
key, //GENERATED/USED KEY
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_compare_time_micro(start_time, finish_time), // ELAPSED TIME
WHY2_SUCCESS //EXIT CODE
};
//DEALLOCATION
why2_deallocate(textKeyChain);
why2_deallocate(textBuffer);
why2_deallocate(text_key_chain);
why2_deallocate(text_buffer);
why2_reset_memory_identifier();

View File

@ -19,11 +19,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h>
#include <stdlib.h>
#include <string.h>
#include <why2/llist.h>
#include <why2/memory.h>
//CONSTS (this is just local)
#define DEFAULT_FLAGS (why2_input_flags) { 0, 0, 0 }
#define DEFAULT_FLAGS (why2_input_flags) { 0, 0, 0, WHY2_v3, WHY2_OUTPUT_TEXT }
#define DEFAULT_MEMORY_IDENTIFIER ""
int encryptionOperation(int text, int encryptedText);
@ -36,66 +38,16 @@ why2_encryption_operation_cb encryptionOperation_cb = encryptionOperation;
why2_bool flagsChanged = 0; //CHANGES TO 1 WHEN U USE why2_set_flags
char *memory_identifier = DEFAULT_MEMORY_IDENTIFIER;
//LINKED LIST SHIT
typedef struct node
{
char *identifier;
struct node *next;
} node_t;
node_t *list_head = NULL;
void push_to_list_end(char *identifier)
{
node_t *new_node = malloc(sizeof(node_t));
node_t *buffer = list_head;
new_node -> identifier = identifier;
new_node -> next = NULL;
if (list_head == NULL) //LIST IS EMTPY
{
list_head = new_node;
} else
{
while (buffer -> next != NULL) buffer = buffer -> next; //GO TO THE END OF LIST
buffer -> next = new_node; //LINK
}
}
void remove_node_from_end(void)
{
if (list_head == NULL) return; //EMPTY LIST
node_t *buffer = list_head;
node_t *deallocating_node;
if (buffer -> next == NULL) //ONLY ONE NODE
{
deallocating_node = buffer;
list_head = NULL;
} else
{
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
deallocating_node = buffer -> next;
buffer -> next = NULL; //UNLINK
}
free(deallocating_node);
}
why2_list_t identifier_list = WHY2_LIST_EMPTY;
char *get_last_node_identifier(void)
{
if (list_head == NULL) return DEFAULT_MEMORY_IDENTIFIER;
if (identifier_list.head == NULL) return DEFAULT_MEMORY_IDENTIFIER;
node_t *buffer = list_head;
why2_node_t *buffer = identifier_list.head;
while (buffer -> next != NULL) buffer = buffer -> next;
return buffer -> identifier;
return buffer -> value;
}
//GETTERS
@ -188,14 +140,14 @@ void why2_set_encryption_operation(why2_encryption_operation_cb newEncryptionOpe
void why2_set_memory_identifier(char *new_memory_identifier)
{
push_to_list_end(new_memory_identifier);
why2_list_push(&identifier_list, new_memory_identifier, strlen(new_memory_identifier) + 1); //TODO: Check memory problems
memory_identifier = new_memory_identifier;
}
void why2_reset_memory_identifier(void)
{
remove_node_from_end();
why2_list_remove_back(&identifier_list);
memory_identifier = get_last_node_identifier();
}

View File

@ -43,7 +43,9 @@ int main(void)
{
0, //SKIP CHECK
0, //NO OUTPUT
0 //UPDATE
0, //UPDATE
WHY2_v3, //LATEST VERSION
WHY2_OUTPUT_TEXT //READABLE TEXT OUTPUT
};
//SET FLAGS

154
src/core/lib/utils/llist.c Normal file
View File

@ -0,0 +1,154 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <why2/llist.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void why2_list_push(why2_list_t *list, void *value, unsigned long size)
{
//CREATE NODE
why2_node_t *head = list -> head;
why2_node_t *new_node = malloc(sizeof(why2_node_t));
new_node -> value = malloc(size);
why2_node_t *buffer = head;
//INSERT DATA
memcpy(new_node -> value, value, size);
new_node -> next = NULL;
if (head == NULL) //INIT LIST
{
buffer = new_node;
} else
{
why2_node_t *buffer_2 = buffer;
while (buffer -> next != NULL) buffer = buffer -> next; //GET TO THE END OF LIST
buffer -> next = new_node; //LINK
buffer = buffer_2; //GO BACK TO THE START OF THE LLIST
}
//APPEND THE new_node TO THE END OF list
list -> head = buffer;
}
void why2_list_remove(why2_list_t *list, why2_node_t *node)
{
if (node == NULL) return; //NULL NODE
why2_node_t *head = list -> head;
why2_node_t *buffer_1 = head;
why2_node_t *buffer_2;
while (buffer_1 -> next != NULL) //GO TROUGH EVERY ELEMENT IN LIST
{
if (buffer_1 == node) break; //FOUND (IF THE WHILE GOES TROUGH THE WHOLE LIST WITHOUT THE break, I ASSUME THE LAST NODE IS THE CORRECT ONE)
buffer_1 = buffer_1 -> next;
}
if (node != buffer_1) return; //node WASN'T FOUND
if (buffer_1 == head) //node WAS THE FIRST NODE IN THE LIST
{
//UNLINK
head = buffer_1 -> next;
} else //wdyt
{
//GET THE NODE BEFORE node
buffer_2 = head;
while (buffer_2 -> next != buffer_1) buffer_2 = buffer_2 -> next;
//UNLINK
buffer_2 -> next = buffer_1 -> next;
}
list -> head = head;
//DEALLOCATION
free(node -> value);
free(node);
}
void why2_list_remove_back(why2_list_t *list)
{
why2_node_t *head = list -> head;
if (head == NULL) return; //EMPTY LIST
why2_node_t *buffer = head;
why2_node_t *deallocating_node;
if (buffer -> next == NULL) //ONLY ONE NODE
{
deallocating_node = buffer;
list -> head = NULL;
} else
{
while (buffer -> next -> next != NULL) buffer = buffer -> next; //GO TO THE NODE BEFORE END
deallocating_node = buffer -> next;
buffer -> next = NULL; //UNLINK
}
free(deallocating_node -> value);
free(deallocating_node);
}
why2_node_t *why2_list_find(why2_list_t *list, void *value)
{
why2_node_t *head = list -> head;
if (head == NULL) return NULL; //EMPTY LIST
why2_node_t *buffer = head;
while (buffer -> next != NULL)
{
if (buffer -> value == value) return buffer;
buffer = buffer -> next;
}
if (value != buffer -> value) buffer = NULL; //PREVENT FROM RETURNING INVALID NODE
return buffer;
}
unsigned long why2_list_get_size(why2_list_t *list)
{
unsigned long n = 0; //RETURNING SIZE
why2_node_t *head = list -> head;
if (head == NULL) return n; //EMPTY LIST
why2_node_t *buffer = head;
do
{
n++;
buffer = buffer -> next; //ITER
} while (buffer != NULL);
return n;
}

View File

@ -1,3 +1,21 @@
/*
This is part of WHY2
Copyright (C) 2022 Václav Šmejkal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
bro this whole file is fucked up af...
@ -55,6 +73,8 @@ void push_to_list(void *pointer, enum POINTER_TYPES type)
void remove_node(node_t *node)
{
if (node == NULL) return; //NULL NODE
node_t *buffer_1 = head;
node_t *buffer_2;
@ -88,7 +108,7 @@ void remove_node(node_t *node)
node_t *get_node(void *pointer)
{
if (head == NULL) return NULL; //EMPTY LIST
if (head == NULL || pointer == NULL) return NULL; //EMPTY LIST
node_t *buffer = head;
while (buffer -> next != NULL)
@ -171,6 +191,8 @@ void *why2_opendir(char *name)
void why2_deallocate(void *pointer)
{
if (pointer == NULL) return; //DEALLOCATING NULL
//VARIABLES
node_t *node = get_node(pointer);
@ -219,3 +241,8 @@ void why2_clean_memory(char *identifier)
why2_reset_memory_identifier(); //THIS WILL CAUSE SEGFAULT IF YOU DIDN'T USE why2_set_memory_identifier
}
why2_bool why2_allocated(void *pointer)
{
return get_node(pointer) != NULL;
}

View File

@ -20,9 +20,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/misc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/random.h>
#include <ftw.h>
#include <curl/curl.h>
@ -32,11 +34,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/flags.h>
#include <why2/memory.h>
why2_bool seedSet = 0; //DO NOT FUCKING TOUCH THIS!!!
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 multiply_cb(int a, int b) { return a * b; }
int subtract_cb(int a, int b) { return a - b; }
int sum_cb(int a, int b) { return a + b; }
int unlink_cb(const char *fpath, WHY2_UNUSED const struct stat *sb, WHY2_UNUSED int typeflag, WHY2_UNUSED struct FTW *ftwbuf)
{
@ -52,40 +52,19 @@ int removeDirectory(char *path)
return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
}
char *replaceWord(char *string, char *old, char *new) //CODE FROM: https://www.geeksforgeeks.org/c-program-replace-word-text-another-given-word
void why2_directory(void)
{
char *result;
int i, cnt = 0;
int newLen = strlen(new);
int oldLen = strlen(old);
struct stat st;
char *buffer = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER"));
for (i = 0; string[i] != '\0'; i++)
//CREATE USER CONFIG FOLDER
if (stat(buffer, &st) == -1)
{
if (strstr(&string[i], old) == &string[i])
{
cnt++;
i += oldLen - 1;
}
mkdir(buffer, 0700);
}
result = (char*) why2_malloc(i + cnt * (newLen - oldLen) + 1);
i = 0;
while (*string)
{
// compare the substring with the result
if (strstr(string, old) == string)
{
strcpy(&result[i], new);
i += newLen;
string += oldLen;
}
else result[i++] = *string++;
}
result[i] = '\0';
return result;
//DEALLOCATION
why2_deallocate(buffer);
}
enum WHY2_EXIT_CODES why2_check_version(void)
@ -93,17 +72,21 @@ enum WHY2_EXIT_CODES why2_check_version(void)
if (why2_get_flags().no_check) return WHY2_SUCCESS;
why2_set_memory_identifier("core_version_check");
why2_directory(); //MAKE SURE WHY2 DIR EXISTS
//FILE-CHECK VARIABLES
int notFoundBuffer = 0;
int not_found_buffer = 0;
//GET VERSION FILE
char *version_file = why2_replace(WHY2_VERSIONS_NAME, "{USER}", getenv("USER"));
//CURL VARIABLES
CURL *curl = curl_easy_init();
FILE *fileBuffer = why2_fopen(WHY2_VERSIONS_NAME, "w+");
FILE *file_buffer = why2_fopen(version_file, "w+");
//GET versions.json
curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fileBuffer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file_buffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
//DOWNLOAD versions.json
@ -111,49 +94,50 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//CLEANUP
curl_easy_cleanup(curl);
why2_deallocate(fileBuffer);
why2_deallocate(file_buffer);
while (access(WHY2_VERSIONS_NAME, R_OK) != 0)
while (access(version_file, R_OK) != 0)
{
notFoundBuffer++;
not_found_buffer++;
if (notFoundBuffer == WHY2_NOT_FOUND_TRIES)
if (not_found_buffer == WHY2_NOT_FOUND_TRIES)
{
if (!why2_get_flags().no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME);
if (!why2_get_flags().no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, version_file);
why2_clean_memory("core_version_check");
return WHY2_DOWNLOAD_FAILED;
}
if (!why2_get_flags().no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME, notFoundBuffer);
if (!why2_get_flags().no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, version_file, not_found_buffer);
sleep(1);
}
//JSON VARIABLES
char *buffer;
struct json_object *parsedJson;
long buffer_size;
struct json_object *parsed_json;
struct json_object *active;
int bufferSize;
//COUNT LENGTH OF buffer AND STORE IT IN bufferSize
fileBuffer = why2_fopen(WHY2_VERSIONS_NAME, "r");
fseek(fileBuffer, 0, SEEK_END);
bufferSize = ftell(fileBuffer);
rewind(fileBuffer); //REWIND fileBuffer (NO SHIT)
file_buffer = why2_fopen(version_file, "r");
fseek(file_buffer, 0, SEEK_END);
buffer_size = ftell(file_buffer);
rewind(file_buffer); //REWIND file_buffer (NO SHIT)
//SET LENGTH OF buffer
buffer = why2_calloc(bufferSize + 1, sizeof(char));
buffer = why2_calloc(buffer_size + 1, sizeof(char));
//LOAD jsonFile
if (fread(buffer, bufferSize, 1, fileBuffer) != 1)
if (fread(buffer, buffer_size, 1, file_buffer) != 1)
{
if (!why2_get_flags().no_output) fprintf(stderr, "Reading file failed!\n");
why2_clean_memory("core_version_check");
return WHY2_DOWNLOAD_FAILED;
// BELOW CODE IS COMMENTED OUT, BECAUSE IT IS PROBABLY UNNECESSARY
// why2_clean_memory("core_version_check");
// return WHY2_DOWNLOAD_FAILED;
}
buffer[bufferSize] = '\0';
buffer[buffer_size] = '\0';
//CHECK FOR TEXT IN buffer
if (strcmp(buffer, "") == 0)
@ -168,11 +152,11 @@ enum WHY2_EXIT_CODES why2_check_version(void)
}
//CLEANUP
why2_deallocate(fileBuffer);
why2_deallocate(file_buffer);
//GET
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);
parsed_json = 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(parsed_json, "active", &active);
if (strcmp(WHY2_VERSION, json_object_get_string(active)) != 0)
{
@ -191,8 +175,8 @@ enum WHY2_EXIT_CODES why2_check_version(void)
//VARIABLES
git_repository *repo = NULL;
int exit_code;
char *installCommand;
int installCode;
char *install_command;
int install_code;
//MESSAGE
if (!why2_get_flags().no_output) printf("Your WHY2 version is outdated!\nUpdating...\t[BETA]\n\n");
@ -218,99 +202,114 @@ enum WHY2_EXIT_CODES why2_check_version(void)
return WHY2_WHY2_UPDATE_FAILED;
}
//COUNT installCommand LENGTH & ALLOCATE IT
installCommand = replaceWord(WHY2_UPDATE_COMMAND, "{DIR}", WHY2_UPDATE_NAME);
//COUNT install_command LENGTH & ALLOCATE IT
install_command = why2_replace(WHY2_UPDATE_COMMAND, "{DIR}", WHY2_UPDATE_NAME);
installCode = system(installCommand); //INSTALL
install_code = system(install_command); //INSTALL
//REMOVE versions.json - OTHERWISE WILL CAUSE SEGFAULT IN NEXT RUN
remove(WHY2_VERSIONS_NAME);
remove(version_file);
why2_deallocate(installCommand);
why2_deallocate(install_command);
//CHECK FOR ERRORS
if (installCode != 0)
if (install_code != 0)
{
if (!why2_get_flags().no_output) fprintf(stderr, "Updating failed! (installing)\n");
why2_clean_memory("core_version_check");
return WHY2_WHY2_UPDATE_FAILED;
}
goto deallocation; //GREAT SUCCESS!
}
//COUNT WHY2_VERSIONS BEHIND
int versionsIndex = -1;
int versionsBuffer = 0;
struct json_object *deprecated;
json_object_object_get_ex(parsedJson, "deprecated", &deprecated);
//COUNT versionsIndex
for (int i = 0; i < (int) json_object_array_length(deprecated); i++)
} else
{
//IT'S A MATCH, BABY :D
if (strcmp(json_object_get_string(json_object_array_get_idx(deprecated, i)), WHY2_VERSION) == 0)
{
versionsIndex = i;
//COUNT WHY2_VERSIONS BEHIND
int versions_index = -1;
int versions_buffer = 0;
break;
struct json_object *deprecated;
json_object_object_get_ex(parsed_json, "deprecated", &deprecated);
//COUNT versions_index
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)), WHY2_VERSION) == 0)
{
versions_index = i;
break;
}
}
//versions.json DOESN'T CONTAIN WHY2_VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT)
if (versions_index == -1)
{
if (!why2_get_flags().no_output) printf("Version %s not found! Check your flags.\n\n", WHY2_VERSION);
} else
{
//COUNT versions_buffer
versions_buffer = json_object_array_length(deprecated) - versions_index;
if (!why2_get_flags().no_output) fprintf(stderr, "This release could be unsafe! You're %d versions behind! (%s/%s)\n\n", versions_buffer, WHY2_VERSION, json_object_get_string(active));
//WAIT FOR 5 SECONDS
sleep(5);
}
}
//versions.json DOESN'T CONTAIN WHY2_VERSION (THIS WILL NOT HAPPEN IF YOU WILL NOT EDIT IT)
if (versionsIndex == -1)
{
if (!why2_get_flags().no_output) printf("Version %s not found! Check your flags.\n\n", WHY2_VERSION);
goto deallocation;
}
//COUNT versionsBuffer
versionsBuffer = json_object_array_length(deprecated) - versionsIndex;
if (!why2_get_flags().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);
}
deallocation:
//DEALLOCATION
json_object_put(parsedJson); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT
json_object_put(parsed_json); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT
why2_deallocate(buffer);
why2_deallocate(version_file);
why2_reset_memory_identifier();
return WHY2_SUCCESS;
}
void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChainSize)
void why2_generate_text_key_chain(char *key, int *text_key_chain, int text_key_chain_size)
{
int numberBuffer;
int numberBuffer2;
double (*cb)(int, int);
int number_buffer;
int number_buffer_2 = 0;
int number_buffer_3 = 0;
int (*cb)(int, int);
for (int i = 0; i < textKeyChainSize; i++)
for (int i = 0; i < text_key_chain_size; i++)
{
numberBuffer = i;
number_buffer = i;
//CHECK, IF numberBuffer ISN'T GREATER THAN keyLength AND CUT WHY2_UNUSED LENGTH
while (numberBuffer >= (int) why2_get_key_length())
//CHECK, IF number_buffer ISN'T GREATER THAN keyLength AND CUT WHY2_UNUSED LENGTH
while (number_buffer >= (int) why2_get_key_length())
{
numberBuffer -= why2_get_key_length();
number_buffer -= why2_get_key_length();
}
numberBuffer2 = why2_get_key_length() - (numberBuffer + (i < textKeyChainSize));
//SET tkch VERSION
switch (why2_get_flags().version)
{
case WHY2_v1:
number_buffer_2 = i;
number_buffer_3 = number_buffer + (i < text_key_chain_size);
break;
case WHY2_v2:
number_buffer_2 = i;
number_buffer_3 = why2_get_key_length() - (number_buffer + (i < text_key_chain_size));
break;
case WHY2_v3:
number_buffer_2 = text_key_chain_size - (i + 1);
number_buffer_3 = why2_get_key_length() - (number_buffer + (i < text_key_chain_size));
break;
}
//FILL textKeyChain
if ((numberBuffer + 1) % 3 == 0)
if ((number_buffer + 1) % 3 == 0)
{
cb = multiply_cb;
}
else if ((numberBuffer + 1) % 2 == 0)
else if ((number_buffer + 1) % 2 == 0)
{
cb = subtract_cb;
}
@ -319,7 +318,7 @@ void why2_generate_text_key_chain(char *key, int *textKeyChain, int textKeyChain
cb = sum_cb;
}
textKeyChain[textKeyChainSize - (i + 1)] = cb(key[numberBuffer], key[numberBuffer2]);
text_key_chain[number_buffer_2] = cb(key[number_buffer], key[number_buffer_3]);
}
}
@ -412,57 +411,83 @@ unsigned long why2_compare_time_micro(struct timeval startTime, struct timeval f
char *why2_generate_key(int key_length)
{
int numberBuffer;
int number_buffer;
unsigned int random_buffer;
char *key;
if (!seedSet)
{
why2_set_memory_identifier("core_key_generation_random");
//TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
FILE *fileBuffer;
fileBuffer = why2_fopen("/dev/urandom", "r");
if (fread(&numberBuffer, sizeof(numberBuffer), 1, fileBuffer) != 1)
{
if (!why2_get_flags().no_output) fprintf(stderr, "Reading file failed!\n");
why2_clean_memory("core_key_generation_random");
return NULL;
}
numberBuffer = abs(numberBuffer); //MAKE numberBuffer POSITIVE
srand(numberBuffer);
why2_deallocate(fileBuffer);
seedSet = 1;
why2_reset_memory_identifier();
}
key = why2_malloc(key_length + 1);
for (int i = 0; i < key_length; i++)
{
//GET RANDOM NUMBER
if (getrandom(&random_buffer, sizeof(unsigned int), GRND_NONBLOCK) == -1) why2_die("getrandom fn failed!");
//SET numberBuffer TO RANDOM NUMBER BETWEEN 0 AND 52
numberBuffer = (rand() % 52) + 1;
number_buffer = (random_buffer % 52) + 1;
//GET CHAR FROM numberBuffer
if (numberBuffer > 26)
if (number_buffer > 26)
{
numberBuffer += 70;
}
else
number_buffer += 70;
} else
{
numberBuffer += 64;
number_buffer += 64;
}
key[i] = (char) numberBuffer;
key[i] = (char) number_buffer;
}
key[key_length] = '\0';
return key;
}
void why2_die(char *exit_msg)
{
fprintf(stderr, "%s\n", exit_msg); //ERR MSG
why2_clean_memory(why2_get_default_memory_identifier()); //GARBAGE COLLECTOR
exit(1);
}
char *why2_replace(char *string, char *old, char *new) //CODE FROM: https://www.geeksforgeeks.org/c-program-replace-word-text-another-given-word
{
char *result;
int i, cnt = 0;
int newLen = strlen(new);
int oldLen = strlen(old);
for (i = 0; string[i] != '\0'; i++)
{
if (strstr(&string[i], old) == &string[i])
{
cnt++;
i += oldLen - 1;
}
}
result = (char*) why2_malloc(i + cnt * (newLen - oldLen) + 1);
i = 0;
while (*string)
{
// compare the substring with the result
if (strstr(string, old) == string)
{
strcpy(&result[i], new);
i += newLen;
string += oldLen;
}
else result[i++] = *string++;
}
result[i] = '\0';
return result;
}
unsigned short why2_byte_format_length(char *s)
{
return ((s[1] - 1) << 7) | (s[0] - 1); //ADD THE FIRST TWO INDEXES TOGETHER TO GET LENGTH
}

View File

@ -15,7 +15,9 @@ int main(void)
{
1,
1,
0
0,
WHY2_v3,
WHY2_OUTPUT_TEXT
}
);

View File

@ -71,32 +71,29 @@ why2_log_file why2_init_logger(char *directoryPath)
if (buffer > WHY2_MAX_USAGE) //WHY2_MAX_USAGE WAS REACHED
{
file = INVALID_FILE;
goto deallocation;
}
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, WHY2_LOG_LATEST_FORMATTING, directoryPath, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH
latestFilePath = why2_strdup(filePath);
if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS
if (symlink(latestFilePath + (strlen(directoryPath) + 1), latestBuffer) != 0) //CREATE SYMLINK
} else
{
if (!why2_get_flags().no_output) fprintf(stderr, "Creating symlink failed!\n");
sprintf(filePath, WHY2_LOG_FORMATTING, directoryPath, dateBuffer, buffer); //GENERATE LOG-NAME
close(file);
why2_clean_memory("logger_logfile_init");
return why2_empty_log_file();
file = open(filePath, O_RDWR | O_APPEND | O_CREAT, 0644); //CREATE LOG FILE
//CREATE SYMLINK
sprintf(latestBuffer, WHY2_LOG_LATEST_FORMATTING, directoryPath, WHY2_LOG_LATEST); //GENERATE LATEST.log PATH
latestFilePath = why2_strdup(filePath);
if (access(latestBuffer, R_OK) == 0) { unlink(latestBuffer); } //REMOVE SYMLINK IF IT ALREADY EXISTS
if (symlink(latestFilePath + (strlen(directoryPath) + 1), latestBuffer) != 0) //CREATE SYMLINK
{
if (!why2_get_flags().no_output) fprintf(stderr, "Creating symlink failed!\n");
close(file);
why2_clean_memory("logger_logfile_init");
return why2_empty_log_file();
}
}
deallocation:
//DEALLOCATION
why2_deallocate(dateBuffer);
why2_deallocate(latestBuffer);
@ -135,7 +132,7 @@ void why2_write_log(int loggerFile, char *logMessage)
why2_log_flags flags = why2_get_log_flags();
//SET ENCRYPTER FLAGS
if (!why2_get_flags_changed()) why2_set_flags((why2_input_flags) { 0, 1, 0 });
if (!why2_get_flags_changed()) why2_set_flags((why2_input_flags) { 0, 1, 0, WHY2_v3, WHY2_OUTPUT_TEXT });
if (flags.key != NULL) //ENCRYPT TEXT IF KEY WAS CHANGED
{