💾 Archived View for thebackupbox.net › ~epoch › blog › uri-plumbing captured on 2024-12-17 at 10:12:55. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-07-09)

-=-=-=-=-=-=-

the uri plumbing mess

alt+u is set to run:

urilaunch

`urilaunch`

which will collect URIs from a handful of places

(uristart history, clipboard, xwindow-uri, hosted bookmarks)

(TODO: this script may be turned into just: `urilist | choose` and do the same thing)

which gets piped into:

choose

`choose`

choose will use either:

`pmenu`

or:

`dmenu`

to let the user select which line of stdin (a uri and optional comments after first whitespace) to use.

the output of choose gets used as the arguments of:

copy_start_nevermind.sh

`copy_start_nevermind.sh`

(TODO: copy_start_nevermind.sh may be deprecated, as I added in multiple-choice selection to uristart)

copy_start_nevermind.sh uses `choose` again, to let the user choose one of a handful of things to do with the URI.

things like:

uristart, copy, shorten, unshorten,

urititle, QR-image, QR,

run copy_start_nevermind.sh with this URI on a remote computer, and

copy only portions of the URI

I add more things as I think of them.

the remote copy_start_nevermind option currenly uses ssh URIs that do a dumb thing of putting a command in the ssh URI path.

I use this to launch like, VNC on my laptop that is being used as a second screen and is connected to my desktop with:

`barrier`

uristart

`uristart`

uristart was originally meant to be a replacement for xdg-open, but on my system I have xdg-open replaced with copy_start_nevermind.sh

uristart's first order of business is to call out to:

`urigetline.c`

with the uri as an argument and a config file on stdin.

This was originally a shell-script, but the format got a bit wonky because of extra matching options that don't require values

this program parses all of the config file lines and outputs either one or all of the matches.

in uristart's case, urigetline is ran with stdin set to the output of another script:

`uristart.conf`

uristart.conf will cat some files from a few different places, usually ~/.config/uristart.conf

uristart calls out twice to urigetline, once to get only the first matching config line,

and the second time with -a to get all matching config lines.

if those don't match it will (later) let the user pick which line to use for launching the URI.

uristart second order of business is to get SRV records using:

`getsrv`

and rewrite the URI using those.

if the SRV records don't provide a port, and a port wasn't explicitly in the URL, it'll set one based on /etc/services and the URI scheme.

if it got this far, it writes the URI to a log file and then starts the next layer of magic

the uri gets piped (with the line as first arugment, and the output of that is eval'd) into:

uriprintf

`uriprintf`

this is a small script that will, read a URI from stdin, and output the first argument, but with these replacements:

%s for scheme
%u for username
%k for password
%d for domain
%P for port
%p for path
%q for query_string
%f for fragment_id
%U for the whole URI

it does this using sed, xargs, and:

uricut

`uricut`

the first C program I've linked to so far and this is the first program in this repo.

I originally wrote the URI parsing into this file directly, then decided it'd make more sense

to put it into a header file and include it, so the parsing could be used in other C programs easier.

that header is:

uri.h

uri.h

I waned to do the URI parsing without regular expressions, but it is probably

not a good implementation of a URI parser because it doesn't ever return an error.

that might be another function to write later... a URI validator instead of just a parser.

ANYWAY

that got kind of low level. we left off at... uristart evaluating a config line that was uriprintf'd with an input URI.

the format for uristart config lines is like:

`uristart.conf.example`

I'm not going to go through all of the config lines I actually have in my real uristart.conf files because... that'd take kind of forever.

so, I guess for feed URIs because that uses a handful of neat things.

TODO: finish putting links into here:

none of it is in my git repos atm, so I'm just going to spill shit and link to it later.

s feed:		curl -si '%U' | message_http

todo:put-a-link-to-message_http

curl -si outputs a whole HTTP response, which, itself is content type of:

"message/http"

message_http will read the "HTTP/1.1 200 Ok"-like first line into three env vars,

then it calls out to:

`read_headers`

which was originally meant to parse HTTP request headers server-side, but comes in handy for parsing them client-side too.

it dumps them into the environment and then executes another program that is named in read_header's arguments.

in the case of message_http, the program is message_http itself, but with an argument "stage2"

running message_http with an argument of "stage2" causes message_http to run:

`run_stdio_handler_by_mime_type`

with $HTTP_CONTENT_TYPE as its first argument.

this script is a switch that contains different things to run... on stdio.. based on mime-type...

the script name is kind of descriptive. *blinks*

for application/atom+xml, it runs atom2uri-list that has a single call to xmlstarlet that rewrite the feed into a uri-list

and then it pipes the output of that script to run_stdio_handler_by_mime_type with text/uri-list as the first argument.

and text/uri-list data is handled by piping the list into `choose` and then using the choice as an argument for:

`copy_start_nevermind.sh`