-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: veilid-hacks
action: blob
revision:
path_from: veilid-appmessage
revision_from: refs/heads/trunk:
path_to:
revision_to:

git.thebackupbox.net

veilid-hacks

git://git.thebackupbox.net/veilid-hacks

blob of:

veilid-hacks

/ veilid-appmessage

refs/heads/trunk:/veilid-appmessage
 #!/usr/bin/env bash

 export keys_dir=~/projects/veilid-hacks/keys

 if [ ! "$1" ];then
   printf 'usage: veilid-appmessage <route> <value>\n' >&2
   exit 1
 fi

 if [ "$1" != "socat" ];then
   export route_id="$1"
   shift
   export input="$*"
   exec socat "tcp:${VEILID_SERVER:-127.0.0.1:5959}" exec:"$0 socat" 2>&1
 else
   shift
 fi

 data="$(printf '%s' "$input" | enb64url | tr -d '\n' | sed 's/=*$//' | tr -d '\n' )" ### the input data needs to be base64url'd and stripped

 printf '{"op":"NewRoutingContext"}\n'
 state=0
 stdbuf -oL jq -nc 'inputs | select(.type != "Update")' | while read -r line;do
   #printf 'state: %d line: %s\n' "$state" "$line" >&2
   case "$state" in
     0)
       rc_id="$(jq -r .value <<< "${line}")"
       printf '{"op":"RoutingContext","rc_id":%d,"rc_op":"AppMessage","message":"%s","target":"%s"}\n' "${rc_id}" "${data}" "${route_id}"
     ;;
     1)
       printf '\nQUIT :what? this isnt woodshop?\r\n'
     ;;
     *)
       echo 'state: ' "$state" >&2
     ;;
   esac
   state=$[$state+1]
 done #| tee /dev/stderr

-- Response ended

-- Page fetched on Sun Jun 2 09:53:56 2024