Proof-of-Concept BOAWP client/server implementation in PicoLisp https://boawp.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

55 lines
1.5 KiB

#!/usr/bin/env pil
#
# BOAWP proof-of-concept client
#
# Usage: ./client.l <host> <port>
(if (= 3 (length (argv)))
(and
(setq *Host (opt))
(setq *Port (format (opt)))
(setq *Uri (opt)) )
(out 2 (prinl "Usage: client.l <host> <port> <uri>"))
(bye 1) )
(chdir ".modules/picolisp-boawp/HEAD"
(load "libboawp.l") )
(setq *BOAWP_commands (append *BOAWP_default_commands *BOAWP_gemini_commands))
(setq *BOAWP_header_names (append *BOAWP_default_header_names *BOAWP_gemini_header_names))
(de poc-boawp-connect ()
(let Fd (connect *Host *Port)
(if Fd
(prog
(poc-boawp-send Fd)
(poc-boawp-receive Fd) )
(out 2 (prinl "Could not connect to " *Host " on port " *Port))
(bye 1) ]
(de poc-boawp-send (Fd)
(let (Msg
(list
(list (char "B") (char "0") (char "A") (char "^J")) # "B0A\n"
(list 0 "GET")
(list (cons "protocol" "GEMINI") (cons "path" *Uri)) )
Encoded (boawp-encode Msg) )
(out Fd (apply wr Encoded)) ]
(de poc-boawp-receive (Fd)
(catch 'boawp-error
(let Res (boawp-validate Fd)
# TODO: validate the response
(println "Received response: " Res)
(let P (native "@" "malloc" 'N (last (cadr Res)))
(eval (append '(struct P NIL) (last Res) (0)))
(if (=0 (native ".lib/libpilrust.so" "validate_utf8" 'I P))
(let Res (struct P 'S)
(native "@" "free" NIL P)
(prinl Res) )
(println (last Res)) ]
(poc-boawp-connect)
(bye)