Devessier / ssl

Clone of openssl in C for 42 School
GNU General Public License v3.0
0 stars 0 forks source link

Launch interactive shell when no arguments are provided #21

Closed Devessier closed 3 years ago

Devessier commented 3 years ago

When no arguments are provided to the command, that is, launching it like this ./ft_ssl, an interactive shell shall be started.

Also, it means that when writing such command echo "md5 -s lol" | ./ft_ssl we should parse stdin but not launch an interactive shell. For that isatty may help us to discern if stdin is a tty in which we can write and wait for user input, or simply a redirection.

Be careful that the user can execute a command in the interactive shell such as md5, which shall read from stdin too.

OpenSSL interactive shell understands single quotes and double quotes.

The commands available in the interactive shell shall be easily extendable and directly mapped to those usable from command line.

Devessier commented 3 years ago

REPL internals:

  1. When no arguments are passed to ./ft_ssl binary we launch the REPL
  2. We print the prompt
  3. We read STDIN until we reach a \n character or EOF 3.1. If we encounter EOF, we exit the repl 3.2. We fill a buffer of 4096 bytes length (the same value as openssl) ; we can't exceed this size.
  4. We loop on the buffer constructed from step 3.1. 4.2. We create a char** buffer of 4096 / sizeof(char **) 4.3. We split the buffer on white spaces and handle quoting
  5. We execute the command as if it was coming from argv
  6. We go back to 2.