From 53d581797325b2f83da37bfef5e89d6039f9ce9c Mon Sep 17 00:00:00 2001 From: g1n Date: Thu, 8 Jul 2021 17:37:41 +0000 Subject: [PATCH] Some input improvements: -m for 'string message', -i for files input --- laconia | 20 +++++++++++++++----- message.txt | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 message.txt diff --git a/laconia b/laconia index eb29c00..9665830 100755 --- a/laconia +++ b/laconia @@ -10,10 +10,16 @@ error_exit() { usage() { printf "usage: %s [OPTIONS] URI [ARGS]\n" "$PROGNAME" printf "Simple client for spartan protocol\n" + printf "Options: +-h, --help - display this help +-p, --port - change port number (default is 300) +-m, --message - input as string +-i, --input-file - input as file +-u, --url - url to the capsule\n" } request(){ - page=$(printf "$host /$path $post_len\r\n$post\r\n" | nc $host $port) + page=$(printf "$host /$path 0\r\n" | nc $host $port) status=$(echo $page | awk 'NR == 1 {print $1}') meta=$(echo $page | awk 'NR == 1 {$1=="";print}') if [[ $status == 2 ]]; then @@ -28,15 +34,19 @@ request(){ fi } -while getopts ":h:p:i:u:" arg; do +while getopts ":h:p:m:i:u:" arg; do case $arg in h | --help) usage; exit ;; p | --port) export port=$OPTARG ;; - i | --input) - export post=$OPTARG + i | --input-file) + export post=$(cat $OPTARG) + export post_len=$(echo $post | wc -c ) + ;; + m | --message) + export post=$( echo $OPTARG) export post_len=$( echo $post | wc -c ) ;; u | --url) @@ -55,7 +65,7 @@ while getopts ":h:p:i:u:" arg; do echo $url_unparsed is not a Spartan URL fi ;; - * | -* | --*) + *) usage; error_exit "unknown option $1" ;; esac done diff --git a/message.txt b/message.txt new file mode 100644 index 0000000..9e83a28 --- /dev/null +++ b/message.txt @@ -0,0 +1,2 @@ +2.One more test sorry +-- g1n